[ASan/Win] Add a comment about DCL-using-static vs threads
[blocksruntime.git] / test / tsan / mutex_cycle2.c
blobfb2b533a103ee6ab7fa6f735975d2c12e4400885
1 // RUN: %clangxx_tsan %s -o %t
2 // RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s
3 // RUN: echo "deadlock:main" > sup
4 // RUN: TSAN_OPTIONS="detect_deadlocks=1 suppressions=sup" %run %t
5 // RUN: echo "deadlock:zzzz" > sup
6 // RUN: TSAN_OPTIONS="detect_deadlocks=1 suppressions=sup" not %run %t 2>&1 | FileCheck %s
7 #include <pthread.h>
9 int main() {
10 pthread_mutex_t mu1, mu2;
11 pthread_mutex_init(&mu1, NULL);
12 pthread_mutex_init(&mu2, NULL);
14 // mu1 => mu2
15 pthread_mutex_lock(&mu1);
16 pthread_mutex_lock(&mu2);
17 pthread_mutex_unlock(&mu2);
18 pthread_mutex_unlock(&mu1);
20 // mu2 => mu1
21 pthread_mutex_lock(&mu2);
22 pthread_mutex_lock(&mu1);
23 // CHECK: ThreadSanitizer: lock-order-inversion (potential deadlock)
24 pthread_mutex_unlock(&mu1);
25 pthread_mutex_unlock(&mu2);
27 pthread_mutex_destroy(&mu1);
28 pthread_mutex_destroy(&mu2);