1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
8 // Test that signals can be delivered to blocked pthread_cond_wait.
9 // https://github.com/google/sanitizers/issues/498
12 pthread_mutex_t mutex
;
15 void sig_handler(int sig
) {
17 write(2, "SIGNAL\n", sizeof("SIGNAL\n") - 1);
18 barrier_wait(&barrier
);
21 void* my_thread(void* arg
) {
22 pthread_mutex_lock(&mutex
);
24 pthread_cond_wait(&cond
, &mutex
);
25 pthread_mutex_unlock(&mutex
);
30 barrier_init(&barrier
, 2);
32 pthread_mutex_init(&mutex
, 0);
33 pthread_cond_init(&cond
, 0);
35 signal(SIGUSR1
, &sig_handler
);
37 pthread_create(&thr
, 0, &my_thread
, 0);
38 // wait for thread to get inside pthread_cond_wait
39 // (can't use barrier_wait for that)
41 pthread_kill(thr
, SIGUSR1
);
42 barrier_wait(&barrier
);
43 pthread_mutex_lock(&mutex
);
45 pthread_cond_signal(&cond
);
46 pthread_mutex_unlock(&mutex
);
48 fprintf(stderr
, "DONE\n");