summaryrefslogtreecommitdiff
path: root/test/tsan/mutexset6.cc
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2015-01-21 13:50:02 +0000
committerDmitry Vyukov <dvyukov@google.com>2015-01-21 13:50:02 +0000
commit12de706f2fd387981e5925a1e42207934613660f (patch)
tree283f74c94ee89994c1ed8bf052ae7da7d2f8dec7 /test/tsan/mutexset6.cc
parent18422b49071ba5ea813d1b065458d6b81c6ef115 (diff)
tsan: remove sleeps from tests
Even sleep(1) lead to episodical flakes on some machines. Use an invisible by tsan barrier to enforce required execution order instead. This makes the tests deterministic and faster. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@226659 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/mutexset6.cc')
-rw-r--r--test/tsan/mutexset6.cc8
1 files changed, 4 insertions, 4 deletions
diff --git a/test/tsan/mutexset6.cc b/test/tsan/mutexset6.cc
index 07dcc0a73..f4251db69 100644
--- a/test/tsan/mutexset6.cc
+++ b/test/tsan/mutexset6.cc
@@ -1,7 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-#include <pthread.h>
-#include <stdio.h>
-#include <unistd.h>
+#include "test.h"
int Global;
pthread_mutex_t mtx1;
@@ -9,7 +7,7 @@ pthread_spinlock_t mtx2;
pthread_rwlock_t mtx3;
void *Thread1(void *x) {
- sleep(1);
+ barrier_wait(&barrier);
pthread_mutex_lock(&mtx1);
Global++;
pthread_mutex_unlock(&mtx1);
@@ -24,10 +22,12 @@ void *Thread2(void *x) {
Global--;
pthread_spin_unlock(&mtx2);
pthread_rwlock_unlock(&mtx3);
+ barrier_wait(&barrier);
return NULL;
}
int main() {
+ barrier_init(&barrier, 2);
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK: Write of size 4 at {{.*}} by thread T1
// CHECK: (mutexes: write [[M1:M[0-9]+]]):