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 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 4 | // bench.h needs pthread barriers which are not available on OS X |
| 5 | // UNSUPPORTED: darwin |
| 6 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 7 | #include "bench.h" |
| 8 | |
| 9 | const int kMutex = 10; |
| 10 | pthread_mutex_t mtx[kMutex]; |
| 11 | |
| 12 | void thread(int tid) { |
| 13 | for (int i = 0; i < bench_niter; i++) { |
| 14 | int idx = (i % kMutex); |
| 15 | if (tid == 0) |
| 16 | idx = kMutex - idx - 1; |
| 17 | pthread_mutex_lock(&mtx[idx]); |
| 18 | pthread_mutex_unlock(&mtx[idx]); |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | void bench() { |
| 23 | for (int i = 0; i < kMutex; i++) |
| 24 | pthread_mutex_init(&mtx[i], 0); |
| 25 | start_thread_group(2, thread); |
| 26 | } |
| 27 | |
| 28 | // CHECK: DONE |
| 29 | |