brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 0dc96d0 Raw
36 lines · c
1// RUN: %clangxx_tsan %s -o %t2// RUN:                                   not %run %t 2>&1 | FileCheck %s3// RUN: %env_tsan_opts=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s4// RUN: %env_tsan_opts=detect_deadlocks=0     %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED5// RUN: echo "deadlock:main" > %t.supp6// RUN: %env_tsan_opts=suppressions='%t.supp' %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED7// RUN: echo "deadlock:zzzz" > %t.supp8// RUN: %env_tsan_opts=suppressions='%t.supp' not %run %t 2>&1 | FileCheck %s9#include <pthread.h>10#include <stdio.h>11 12int main() {13  pthread_mutex_t mu1, mu2;14  pthread_mutex_init(&mu1, NULL);15  pthread_mutex_init(&mu2, NULL);16 17  // mu1 => mu218  pthread_mutex_lock(&mu1);19  pthread_mutex_lock(&mu2);20  pthread_mutex_unlock(&mu2);21  pthread_mutex_unlock(&mu1);22 23  // mu2 => mu124  pthread_mutex_lock(&mu2);25  pthread_mutex_lock(&mu1);26  // CHECK: ThreadSanitizer: lock-order-inversion (potential deadlock)27  // DISABLED-NOT: ThreadSanitizer28  // DISABLED: PASS29  pthread_mutex_unlock(&mu1);30  pthread_mutex_unlock(&mu2);31 32  pthread_mutex_destroy(&mu1);33  pthread_mutex_destroy(&mu2);34  fprintf(stderr, "PASS\n");35}36