1 // RUN: %clangxx_tsan %s -o %t
2 // RUN: %deflake %run %t 2>&1 | FileCheck %s
10 __attribute__((no_sanitize("thread")))
11 void ExternalWrite(void *addr
) {
12 __tsan_external_write(addr
, __builtin_return_address(0), tag
);
15 int main(int argc
, char *argv
[]) {
16 barrier_init(&barrier
, 2);
17 tag
= __tsan_external_register_tag("HelloWorld");
18 fprintf(stderr
, "Start.\n");
21 for (int i
= 0; i
< 4; i
++) {
22 void *opaque_object
= malloc(16);
23 std::thread
t1([opaque_object
] {
24 ExternalWrite(opaque_object
);
25 barrier_wait(&barrier
);
27 std::thread
t2([opaque_object
] {
28 barrier_wait(&barrier
);
29 ExternalWrite(opaque_object
);
31 // CHECK: WARNING: ThreadSanitizer: race on HelloWorld
36 fprintf(stderr
, "First phase done.\n");
37 // CHECK: First phase done.
39 for (int i
= 0; i
< 4; i
++) {
40 void *opaque_object
= malloc(16);
41 std::thread
t1([opaque_object
] {
42 ExternalWrite(opaque_object
);
43 barrier_wait(&barrier
);
45 std::thread
t2([opaque_object
] {
46 barrier_wait(&barrier
);
47 ExternalWrite(opaque_object
);
49 // CHECK: WARNING: ThreadSanitizer: race on HelloWorld
54 fprintf(stderr
, "Second phase done.\n");
55 // CHECK: Second phase done.
58 // CHECK: ThreadSanitizer: reported 2 warnings