blob: fb6a66136b8af6354673c949c81abc69411ac345 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2// CHECK-NOT: WARNING
3// CHECK: OK
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08004// 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 Hines2d1fdb22014-05-28 23:58:16 -070012
Stephen Hines86277eb2015-03-23 12:06:32 -070013#include "test.h"
Stephen Hines2d1fdb22014-05-28 23:58:16 -070014
15pthread_mutex_t m;
16pthread_cond_t c;
17int x;
18
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -070019static void my_cleanup(void *arg) {
20 printf("my_cleanup\n");
21 pthread_mutex_unlock((pthread_mutex_t*)arg);
22}
23
Stephen Hines2d1fdb22014-05-28 23:58:16 -070024void *thr1(void *p) {
25 pthread_mutex_lock(&m);
Pirama Arumuga Nainar259f7062015-05-06 11:49:53 -070026 pthread_cleanup_push(my_cleanup, &m);
Stephen Hines86277eb2015-03-23 12:06:32 -070027 barrier_wait(&barrier);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070028 while (x == 0)
29 pthread_cond_wait(&c, &m);
30 pthread_cleanup_pop(1);
31 return 0;
32}
33
34int main() {
Stephen Hines86277eb2015-03-23 12:06:32 -070035 barrier_init(&barrier, 2);
36
Stephen Hines2d1fdb22014-05-28 23:58:16 -070037 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 Hines86277eb2015-03-23 12:06:32 -070043 barrier_wait(&barrier);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070044 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}