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

source code of compiler-rt/test/tsan/bench_local_mutex.cpp