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 const int kMutex = 10;
10 pthread_mutex_t mtx[kMutex];
11 
thread(int tid)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 
bench()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 
30