1 // Mini-benchmark for tsan: non-shared memory writes.
9 const int kNumIter
= 1000;
11 __attribute__((noinline
))
13 for (int i
= 0, n
= len
; i
< n
; i
++)
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
);
38 a
= new int[n_threads
* len
];
39 pthread_t
*t
= new pthread_t
[n_threads
];
40 for (int i
= 0; i
< n_threads
; i
++) {
41 pthread_create(&t
[i
], 0, Thread
, (void*)i
);
43 for (int i
= 0; i
< n_threads
; i
++) {
44 pthread_join(t
[i
], 0);