1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s 2 #include "test.h" 3 4 // OS X doesn't have pthread_setname_np(tid, name). 5 // UNSUPPORTED: darwin 6 7 #if defined(__FreeBSD__) 8 #include <pthread_np.h> 9 #define pthread_setname_np pthread_set_name_np 10 #endif 11 12 long long Global; 13 14 void *Thread1(void *x) { 15 barrier_wait(&barrier); 16 Global++; 17 return 0; 18 } 19 20 void *Thread2(void *x) { 21 pthread_setname_np(pthread_self(), "foobar2"); 22 Global--; 23 barrier_wait(&barrier); 24 return 0; 25 } 26 27 int main() { 28 barrier_init(&barrier, 3); 29 pthread_t t[2]; 30 pthread_create(&t[0], 0, Thread1, 0); 31 pthread_create(&t[1], 0, Thread2, 0); 32 pthread_setname_np(t[0], "foobar1"); 33 barrier_wait(&barrier); 34 pthread_join(t[0], NULL); 35 pthread_join(t[1], NULL); 36 } 37 38 // CHECK: WARNING: ThreadSanitizer: data race 39 // CHECK: Thread T1 'foobar1' 40 // CHECK: Thread T2 'foobar2' 41