| 1 | // RUN: %clangxx_tsan %s -o %t |
|---|---|
| 2 | // RUN: %run %t 2>&1 | FileCheck %s |
| 3 | |
| 4 | // bench.h needs pthread barriers which are not available on OS X |
| 5 | // UNSUPPORTED: darwin |
| 6 | |
| 7 | #include "bench.h" |
| 8 | |
| 9 | pthread_mutex_t mtx; |
| 10 | pthread_cond_t cv; |
| 11 | int x; |
| 12 | |
| 13 | void thread(int tid) { |
| 14 | for (int i = 0; i < bench_niter; i++) { |
| 15 | pthread_mutex_lock(mutex: &mtx); |
| 16 | while (x != i * 2 + tid) |
| 17 | pthread_cond_wait(cond: &cv, mutex: &mtx); |
| 18 | x++; |
| 19 | pthread_cond_signal(cond: &cv); |
| 20 | pthread_mutex_unlock(mutex: &mtx); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | void bench() { |
| 25 | pthread_mutex_init(mutex: &mtx, mutexattr: 0); |
| 26 | pthread_cond_init(cond: &cv, cond_attr: 0); |
| 27 | start_thread_group(nth: 2, f: thread); |
| 28 | } |
| 29 | |
| 30 | // CHECK: DONE |
| 31 | |
| 32 |
