1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
4 // OS X doesn't have pthread_setname_np(tid, name).
7 #if defined(__FreeBSD__)
8 #include <pthread_np.h>
9 #define tsan_pthread_setname_np pthread_set_name_np
10 #elif defined(__NetBSD__)
11 #define tsan_pthread_setname_np(a, b) pthread_setname_np((a), "%s", (void *)(b))
13 #define tsan_pthread_setname_np pthread_setname_np
18 void *Thread1(void *x
) {
19 barrier_wait(&barrier
);
24 void *Thread2(void *x
) {
25 tsan_pthread_setname_np(pthread_self(), "foobar2");
27 barrier_wait(&barrier
);
32 barrier_init(&barrier
, 3);
34 pthread_create(&t
[0], 0, Thread1
, 0);
35 pthread_create(&t
[1], 0, Thread2
, 0);
36 tsan_pthread_setname_np(t
[0], "foobar1");
37 barrier_wait(&barrier
);
38 pthread_join(t
[0], NULL
);
39 pthread_join(t
[1], NULL
);
42 // CHECK: WARNING: ThreadSanitizer: data race
43 // CHECK: Thread T1 'foobar1'
44 // CHECK: Thread T2 'foobar2'