[compiler-rt] r212944 - [tsan] add a currently-failing test with a must-deadlock
Kostya Serebryany
kcc at google.com
Mon Jul 14 07:27:22 PDT 2014
Author: kcc
Date: Mon Jul 14 09:27:21 2014
New Revision: 212944
URL: http://llvm.org/viewvc/llvm-project?rev=212944&view=rev
Log:
[tsan] add a currently-failing test with a must-deadlock
Added:
compiler-rt/trunk/test/tsan/must_deadlock.cc
Added: compiler-rt/trunk/test/tsan/must_deadlock.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/tsan/must_deadlock.cc?rev=212944&view=auto
==============================================================================
--- compiler-rt/trunk/test/tsan/must_deadlock.cc (added)
+++ compiler-rt/trunk/test/tsan/must_deadlock.cc Mon Jul 14 09:27:21 2014
@@ -0,0 +1,49 @@
+// Test that the deadlock detector can find a deadlock that actually happened.
+// Currently we will fail to report such a deadlock because we check for
+// cycles in lock-order graph after pthread_mutex_lock.
+
+// RUN: %clangxx_tsan %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// XFAIL: *
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+
+pthread_mutex_t mu1, mu2;
+pthread_barrier_t barrier;
+
+void *Thread(void *p) {
+ // mu2 => mu1
+ pthread_mutex_lock(&mu2);
+ pthread_barrier_wait(&barrier);
+ pthread_mutex_lock(&mu1);
+ // CHECK: ThreadSanitizer: lock-order-inversion (potential deadlock)
+ pthread_mutex_unlock(&mu1);
+ pthread_mutex_unlock(&mu2);
+ return p;
+}
+
+int main() {
+ pthread_mutex_init(&mu1, NULL);
+ pthread_mutex_init(&mu2, NULL);
+ pthread_barrier_init(&barrier, 0, 2);
+
+ alarm(3);
+
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+
+ // mu1 => mu2
+ pthread_mutex_lock(&mu1);
+ pthread_barrier_wait(&barrier);
+ pthread_mutex_lock(&mu2);
+ pthread_mutex_unlock(&mu2);
+ pthread_mutex_unlock(&mu1);
+
+ pthread_join(t, 0);
+
+ pthread_mutex_destroy(&mu1);
+ pthread_mutex_destroy(&mu2);
+ pthread_barrier_destroy(&barrier);
+ fprintf(stderr, "FAILED\n");
+}
More information about the llvm-commits
mailing list