1 // RUN: %clangxx_tsan -O1 %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s
3 // RUN: %run %t arg 2>&1 | FileCheck %s
4 // RUN: %run %t arg arg 2>&1 | FileCheck %s
7 // Test for destruction of pthread_cond_t.
8 // POSIX states that it is safe to destroy a condition variable upon which no
9 // threads are currently blocked. That is, it is not necessary to wait untill
10 // other threads return from pthread_cond_wait, they just need to be unblocked.
17 pthread_mutex_lock(&m
);
19 pthread_cond_signal(&c
);
21 pthread_cond_wait(&c
, &m
);
22 pthread_mutex_unlock(&m
);
26 int main(int argc
, char **argv
) {
28 pthread_mutex_init(&m
, 0);
29 pthread_cond_init(&c
, 0);
30 pthread_create(&th
, 0, thr
, 0);
31 pthread_mutex_lock(&m
);
33 pthread_cond_wait(&c
, &m
);
35 // Any of these sequences is legal.
37 pthread_cond_signal(&c
);
38 pthread_mutex_unlock(&m
);
39 pthread_cond_destroy(&c
);
40 } else if (argc
== 2) {
41 pthread_mutex_unlock(&m
);
42 pthread_cond_signal(&c
);
43 pthread_cond_destroy(&c
);
45 pthread_cond_signal(&c
);
46 pthread_cond_destroy(&c
);
47 pthread_mutex_unlock(&m
);
50 fprintf(stderr
, "DONE\n");
53 // CHECK-NOT: ThreadSanitizer: data race