diff options
author | Alexey Samsonov <samsonov@google.com> | 2014-02-14 14:35:48 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2014-02-14 14:35:48 +0000 |
commit | e6a6183e9b8ecf7dec8808fa87577d5b574ca22e (patch) | |
tree | a6e5f3181f2e0c4ffc21f9648c5e9c873f34b330 /compiler-rt/test/tsan/cond_race.cc | |
parent | 9f20d6703479a952465f7db0c2fbd70904c030c2 (diff) | |
download | bcm5719-llvm-e6a6183e9b8ecf7dec8808fa87577d5b574ca22e.tar.gz bcm5719-llvm-e6a6183e9b8ecf7dec8808fa87577d5b574ca22e.zip |
Move TSan lit-tests under test/tsan
llvm-svn: 201414
Diffstat (limited to 'compiler-rt/test/tsan/cond_race.cc')
-rw-r--r-- | compiler-rt/test/tsan/cond_race.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/compiler-rt/test/tsan/cond_race.cc b/compiler-rt/test/tsan/cond_race.cc new file mode 100644 index 00000000000..1e2acb24327 --- /dev/null +++ b/compiler-rt/test/tsan/cond_race.cc @@ -0,0 +1,36 @@ +// RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s +// CHECK: ThreadSanitizer: data race +// CHECK: pthread_cond_signal + +#include <stdio.h> +#include <stdlib.h> +#include <pthread.h> + +struct Ctx { + pthread_mutex_t m; + pthread_cond_t c; + bool done; +}; + +void *thr(void *p) { + Ctx *c = (Ctx*)p; + pthread_mutex_lock(&c->m); + c->done = true; + pthread_mutex_unlock(&c->m); + pthread_cond_signal(&c->c); + return 0; +} + +int main() { + Ctx *c = new Ctx(); + pthread_mutex_init(&c->m, 0); + pthread_cond_init(&c->c, 0); + pthread_t th; + pthread_create(&th, 0, thr, c); + pthread_mutex_lock(&c->m); + while (!c->done) + pthread_cond_wait(&c->c, &c->m); + pthread_mutex_unlock(&c->m); + delete c; + pthread_join(th, 0); +} |