Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_tsan %s -o %t |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 2 | // RUN: not %run %t 2>&1 | FileCheck %s |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 3 | // RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 4 | // RUN: TSAN_OPTIONS=detect_deadlocks=0 %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 5 | // RUN: echo "deadlock:main" > %t.supp |
| 6 | // RUN: TSAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED |
| 7 | // RUN: echo "deadlock:zzzz" > %t.supp |
| 8 | // RUN: TSAN_OPTIONS="suppressions='%t.supp'" not %run %t 2>&1 | FileCheck %s |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 9 | #include <pthread.h> |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 10 | #include <stdio.h> |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 11 | |
| 12 | int main() { |
| 13 | pthread_mutex_t mu1, mu2; |
| 14 | pthread_mutex_init(&mu1, NULL); |
| 15 | pthread_mutex_init(&mu2, NULL); |
| 16 | |
| 17 | // mu1 => mu2 |
| 18 | pthread_mutex_lock(&mu1); |
| 19 | pthread_mutex_lock(&mu2); |
| 20 | pthread_mutex_unlock(&mu2); |
| 21 | pthread_mutex_unlock(&mu1); |
| 22 | |
| 23 | // mu2 => mu1 |
| 24 | pthread_mutex_lock(&mu2); |
| 25 | pthread_mutex_lock(&mu1); |
| 26 | // CHECK: ThreadSanitizer: lock-order-inversion (potential deadlock) |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 27 | // DISABLED-NOT: ThreadSanitizer |
| 28 | // DISABLED: PASS |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 29 | pthread_mutex_unlock(&mu1); |
| 30 | pthread_mutex_unlock(&mu2); |
| 31 | |
| 32 | pthread_mutex_destroy(&mu1); |
| 33 | pthread_mutex_destroy(&mu2); |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 34 | fprintf(stderr, "PASS\n"); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 35 | } |