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 const int kStride = 16;
8 
thread(int tid)9 void thread(int tid) {
10   for (int i = 0; i < bench_niter; i++) {
11     pthread_mutex_lock(&mtx[tid * kStride]);
12     pthread_mutex_unlock(&mtx[tid * kStride]);
13   }
14 }
15 
bench()16 void bench() {
17   mtx = (pthread_mutex_t*)malloc(bench_nthread * kStride * sizeof(*mtx));
18   for (int i = 0; i < bench_nthread; i++) {
19     pthread_mutex_init(&mtx[i * kStride], 0);
20     pthread_mutex_lock(&mtx[i * kStride]);
21     pthread_mutex_unlock(&mtx[i * kStride]);
22   }
23   start_thread_group(bench_nthread, thread);
24 }
25 
26 // CHECK: DONE
27 
28