Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_tsan %s -o %t |
| 2 | // RUN: %run %t 2>&1 | FileCheck %s |
| 3 | |
| 4 | #include "bench.h" |
| 5 | |
| 6 | pthread_mutex_t mtx; |
| 7 | pthread_cond_t cv; |
| 8 | int x; |
| 9 | |
| 10 | void thread(int tid) { |
| 11 | for (int i = 0; i < bench_niter; i++) { |
| 12 | pthread_mutex_lock(&mtx); |
| 13 | while (x != i * 2 + tid) |
| 14 | pthread_cond_wait(&cv, &mtx); |
| 15 | x++; |
| 16 | pthread_cond_signal(&cv); |
| 17 | pthread_mutex_unlock(&mtx); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | void bench() { |
| 22 | pthread_mutex_init(&mtx, 0); |
| 23 | pthread_cond_init(&cv, 0); |
| 24 | start_thread_group(2, thread); |
| 25 | } |
| 26 | |
| 27 | // CHECK: DONE |
| 28 | |