Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s |
| 2 | // CHECK-NOT: WARNING |
| 3 | // CHECK: OK |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 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 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 12 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 13 | #include "test.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 14 | |
| 15 | pthread_mutex_t m; |
| 16 | pthread_cond_t c; |
| 17 | int x; |
| 18 | |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 19 | static void my_cleanup(void *arg) { |
| 20 | printf("my_cleanup\n"); |
| 21 | pthread_mutex_unlock((pthread_mutex_t*)arg); |
| 22 | } |
| 23 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 24 | void *thr1(void *p) { |
| 25 | pthread_mutex_lock(&m); |
Pirama Arumuga Nainar | 259f706 | 2015-05-06 11:49:53 -0700 | [diff] [blame] | 26 | pthread_cleanup_push(my_cleanup, &m); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 27 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 28 | while (x == 0) |
| 29 | pthread_cond_wait(&c, &m); |
| 30 | pthread_cleanup_pop(1); |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 35 | barrier_init(&barrier, 2); |
| 36 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 43 | barrier_wait(&barrier); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 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 | } |