1 // Test that the deadlock detector can find a deadlock that actually happened.
2 // Currently we will fail to report such a deadlock because we check for
3 // cycles in lock-order graph after pthread_mutex_lock.
5 // RUN: %clangxx_tsan %s -o %t
6 // RUN: not %run %t 2>&1 | FileCheck %s
12 pthread_mutex_t mu1
, mu2
;
13 pthread_barrier_t barrier
;
15 void *Thread(void *p
) {
17 pthread_mutex_lock(&mu2
);
18 pthread_barrier_wait(&barrier
);
19 pthread_mutex_lock(&mu1
);
20 // CHECK: ThreadSanitizer: lock-order-inversion (potential deadlock)
21 pthread_mutex_unlock(&mu1
);
22 pthread_mutex_unlock(&mu2
);
27 pthread_mutex_init(&mu1
, NULL
);
28 pthread_mutex_init(&mu2
, NULL
);
29 pthread_barrier_init(&barrier
, 0, 2);
31 fprintf(stderr
, "This test is going to deadlock and die in 3 seconds\n");
35 pthread_create(&t
, 0, Thread
, 0);
38 pthread_mutex_lock(&mu1
);
39 pthread_barrier_wait(&barrier
);
40 pthread_mutex_lock(&mu2
);
41 pthread_mutex_unlock(&mu2
);
42 pthread_mutex_unlock(&mu1
);
46 pthread_mutex_destroy(&mu1
);
47 pthread_mutex_destroy(&mu2
);
48 pthread_barrier_destroy(&barrier
);
49 fprintf(stderr
, "FAILED\n");