aboutsummaryrefslogtreecommitdiff
path: root/test/tsan/cond_cancel.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/tsan/cond_cancel.c')
-rw-r--r--test/tsan/cond_cancel.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/test/tsan/cond_cancel.c b/test/tsan/cond_cancel.c
index 397cad4b1838..e744570b12fc 100644
--- a/test/tsan/cond_cancel.c
+++ b/test/tsan/cond_cancel.c
@@ -2,10 +2,7 @@
// CHECK-NOT: WARNING
// CHECK: OK
-#include <stdio.h>
-#include <stdlib.h>
-#include <pthread.h>
-#include <unistd.h>
+#include "test.h"
pthread_mutex_t m;
pthread_cond_t c;
@@ -14,6 +11,7 @@ int x;
void *thr1(void *p) {
pthread_mutex_lock(&m);
pthread_cleanup_push((void(*)(void *arg))pthread_mutex_unlock, &m);
+ barrier_wait(&barrier);
while (x == 0)
pthread_cond_wait(&c, &m);
pthread_cleanup_pop(1);
@@ -21,12 +19,15 @@ void *thr1(void *p) {
}
int main() {
+ barrier_init(&barrier, 2);
+
pthread_t th;
pthread_mutex_init(&m, 0);
pthread_cond_init(&c, 0);
pthread_create(&th, 0, thr1, 0);
+ barrier_wait(&barrier);
sleep(1); // let it block on cond var
pthread_cancel(th);