% cc pthr_prime.c -lm -mt -xinstrument=datarace .
% collect -r on a.out | sort -n
Creating experiment database test.2.er ...
of type "nfs", which may distort the measured performance.
0
0
0
0
0
0
0
0
0
0
...
0
0
Creating experiment database test.2.er ...
Number of prime numbers between 2 and 3000: 328
751
757
761
773
797
809
811
821
823
827
829
839
853
857
859
877
881
883
887
907
...
2999
2999
% er_print test.2.er
(er_print) races
Total Races: 6 Experiment: test.2.er
Race #1, Vaddr: 0x218d0
Access 1: Write, work + 0x00000154,
line 40 in "pthr_prime.c"
Access 2: Write, work + 0x00000154,
line 40 in "pthr_prime.c"
Total Traces: 3
Race #2, Vaddr: 0x218d0
Access 1: Read, work + 0x000000CC,
line 39 in "pthr_prime.c"
Access 2: Write, work + 0x00000154,
line 40 in "pthr_prime.c"
Total Traces: 3
Race #3, Vaddr: 0xffbfeec4
Access 1: Write, main + 0x00000204,
line 55 in "pthr_prime.c"
Access 2: Read, work + 0x00000024,
line 35 in "pthr_prime.c"
Total Traces: 2
Race #4, Vaddr: (Multiple Addresses)
Access 1: Write, work + 0x00000108,
line 39 in "pthr_prime.c"
Access 2: Write, work + 0x00000108,
line 39 in "pthr_prime.c"
Total Traces: 1
Race #5, Vaddr: 0x23bfc
Access 1: Write, is_prime + 0x00000210,
line 22 in "pthr_prime.c"
Access 2: Write, is_prime + 0x00000210,
line 22 in "pthr_prime.c"
Total Traces: 1
Race #6, Vaddr: 0x247bc
Access 1: Write, work + 0x00000108,
line 39 in "pthr_prime.c"
Access 2: Read, main + 0x00000394,
line 65 in "pthr_prime.c"
Total Traces: 1
(er_print)
以下屏幕快照显示在 pthr_primes.c 中检测到的争用,与线程分析器 GUI 显示的相同。调用 GUI 和装入实验数据的命令是 tha test.2.er。

在 pthr_prime.c 中有以下六个数据争用:
一号争用:第 40 行上 total 的写入和同一行上 total 的另一写入之间的数据争用。
二号争用:第 39 行上 total 的读取和第 40 行上 total 的写入之间的数据争用。
三号争用:第 55 行上 i 的写入和第 35 行上 i 的读取之间的数据争用。
四号争用:第 39 行上primes[] 的写入和同一行上primes[] 的另一写入之间的数据争用。
五号争用:第 22 行上 pflag[] 的写入和同一行上 pflag[] 的另一写入之间的数据争用
六号争用:第 39 行上 primes[] 的写入和第 65 行上 primes[] 的读取之间的数据争用。
GUI 的一个优势在于,它允许您并排查看与数据争用关联的两个源位置。例如,在 Races(争用)选项卡中选择 pthr_prime.c 的六号争用,然后单击“双重数据源”选项卡。您将看到以下内容:

在顶部 "Race Source" 窗格中显示六号争用(第 39 行)的第一次访问,在底部窗格中则显示该数据争用的第二次访问。突出显示其中发生数据争用访问的源代码(第 39 行和第 65 行)。在每个源代码行的左侧显示缺省度量(互斥争用访问度量)。该度量显示在该行上报告的数据争用访问次数。