diff options
author | Dmitry Vyukov <dvyukov@google.com> | 2015-01-21 13:50:02 +0000 |
---|---|---|
committer | Dmitry Vyukov <dvyukov@google.com> | 2015-01-21 13:50:02 +0000 |
commit | 12de706f2fd387981e5925a1e42207934613660f (patch) | |
tree | 283f74c94ee89994c1ed8bf052ae7da7d2f8dec7 /test/tsan/thread_name2.cc | |
parent | 18422b49071ba5ea813d1b065458d6b81c6ef115 (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/thread_name2.cc')
-rw-r--r-- | test/tsan/thread_name2.cc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/test/tsan/thread_name2.cc b/test/tsan/thread_name2.cc index 6a3dafe9c..a44f4b9d3 100644 --- a/test/tsan/thread_name2.cc +++ b/test/tsan/thread_name2.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" #if defined(__FreeBSD__) #include <pthread_np.h> @@ -11,7 +9,7 @@ int Global; void *Thread1(void *x) { - sleep(1); + barrier_wait(&barrier); Global++; return 0; } @@ -19,14 +17,17 @@ void *Thread1(void *x) { void *Thread2(void *x) { pthread_setname_np(pthread_self(), "foobar2"); Global--; + barrier_wait(&barrier); return 0; } int main() { + barrier_init(&barrier, 3); pthread_t t[2]; pthread_create(&t[0], 0, Thread1, 0); pthread_create(&t[1], 0, Thread2, 0); pthread_setname_np(t[0], "foobar1"); + barrier_wait(&barrier); pthread_join(t[0], NULL); pthread_join(t[1], NULL); } |