1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 // CHECK-NOT: ThreadSanitizer: data race
5 // pthread barriers are not available on OS X
14 volatile int kIter
= 10; // prevent unwinding
16 pthread_barrier_t barrier
;
19 int idx
= (int)(long)p
;
20 for (int i
= 0; i
< kIter
; i
++) {
21 int *prev
= data
[i
% 2];
22 int *curr
= data
[(i
+ 1) % 2];
23 int left
= idx
- 1 >= 0 ? prev
[idx
- 1] : 0;
24 int right
= idx
+ 1 < kSize
? prev
[idx
+ 1] : 0;
25 curr
[idx
] = (left
+ right
) / 2;
26 pthread_barrier_wait(&barrier
);
32 pthread_barrier_init(&barrier
, 0, kSize
);
34 for (int i
= 0; i
< kSize
; i
++)
35 pthread_create(&th
[i
], 0, thr
, (void*)(long)i
);
36 for (int i
= 0; i
< kSize
; i
++)
37 pthread_join(th
[i
], 0);
38 pthread_barrier_destroy(&barrier
);
39 fprintf(stderr
, "DONE\n");