[Sanitizer] Add rudimentary support for wide-character strings to scanf/printf interc...
[blocksruntime.git] / test / tsan / mutex_cycle2.c
blobbb4c1b04938efa8ae3c4bb26cabbbaa260a3b0c9
1 // RUN: %clangxx_tsan %s -o %t
2 // RUN: TSAN_OPTIONS=detect_deadlocks=1 not %t 2>&1 | FileCheck %s
3 // RUN: echo "deadlock:main" > sup
4 // RUN: TSAN_OPTIONS="detect_deadlocks=1 suppressions=sup" %t
5 // RUN: echo "deadlock:zzzz" > sup
6 // RUN: TSAN_OPTIONS="detect_deadlocks=1 suppressions=sup" not %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);