1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s 2 // CHECK-NOT: WARNING 3 // CHECK: OK 4 // This test is failing on powerpc64 (VMA=44). After calling pthread_cancel, 5 // the Thread-specific data destructors are not called, so the destructor 6 // "thread_finalize" (defined in tsan_interceptors.cc) can not set the status 7 // of the thread to "ThreadStatusFinished" failing a check in "SetJoined" 8 // (defined in sanitizer_thread_registry.cc). It might seem a bug on glibc, 9 // however the same version GLIBC-2.17 will not make fail the test on 10 // powerpc64 BE (VMA=46) 11 // XFAIL: powerpc64-unknown-linux-gnu 12 13 #include "test.h" 14 15 pthread_mutex_t m; 16 pthread_cond_t c; 17 int x; 18 19 static void my_cleanup(void *arg) { 20 printf("my_cleanup\n"); 21 pthread_mutex_unlock((pthread_mutex_t*)arg); 22 } 23 24 void *thr1(void *p) { 25 pthread_mutex_lock(&m); 26 pthread_cleanup_push(my_cleanup, &m); 27 barrier_wait(&barrier); 28 while (x == 0) 29 pthread_cond_wait(&c, &m); 30 pthread_cleanup_pop(1); 31 return 0; 32 } 33 34 int main() { 35 barrier_init(&barrier, 2); 36 37 pthread_t th; 38 39 pthread_mutex_init(&m, 0); 40 pthread_cond_init(&c, 0); 41 42 pthread_create(&th, 0, thr1, 0); 43 barrier_wait(&barrier); 44 sleep(1); // let it block on cond var 45 pthread_cancel(th); 46 47 pthread_join(th, 0); 48 pthread_mutex_lock(&m); 49 pthread_mutex_unlock(&m); 50 fprintf(stderr, "OK\n"); 51 } 52