1 // Mini-benchmark for tsan: shared memory reads.
9 const int kNumIter
= 1000;
11 __attribute__((noinline
))
13 for (int i
= 0, n
= len
; i
< n
; i
++)
14 if (a
[i
] != i
) abort();
17 void *Thread(void *arg
) {
19 printf("Thread %ld started\n", idx
);
20 for (int i
= 0; i
< kNumIter
; i
++)
22 printf("Thread %ld done\n", idx
);
26 int main(int argc
, char **argv
) {
32 n_threads
= atoi(argv
[1]);
33 assert(n_threads
> 0 && n_threads
<= 32);
36 printf("%s: n_threads=%d len=%d iter=%d\n",
37 __FILE__
, n_threads
, len
, kNumIter
);
39 for (int i
= 0, n
= len
; i
< n
; i
++)
41 pthread_t
*t
= new pthread_t
[n_threads
];
42 for (int i
= 0; i
< n_threads
; i
++) {
43 pthread_create(&t
[i
], 0, Thread
, (void*)i
);
45 for (int i
= 0; i
< n_threads
; i
++) {
46 pthread_join(t
[i
], 0);