xref: /aosp_15_r20/external/compiler-rt/test/tsan/bench_ten_mutexes.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_tsan %s -o %t
2*7c3d14c8STreehugger Robot // RUN: %run %t 2>&1 | FileCheck %s
3*7c3d14c8STreehugger Robot 
4*7c3d14c8STreehugger Robot // bench.h needs pthread barriers which are not available on OS X
5*7c3d14c8STreehugger Robot // UNSUPPORTED: darwin
6*7c3d14c8STreehugger Robot 
7*7c3d14c8STreehugger Robot #include "bench.h"
8*7c3d14c8STreehugger Robot 
9*7c3d14c8STreehugger Robot const int kMutex = 10;
10*7c3d14c8STreehugger Robot pthread_mutex_t mtx[kMutex];
11*7c3d14c8STreehugger Robot 
thread(int tid)12*7c3d14c8STreehugger Robot void thread(int tid) {
13*7c3d14c8STreehugger Robot   for (int i = 0; i < bench_niter; i++) {
14*7c3d14c8STreehugger Robot     int idx = (i % kMutex);
15*7c3d14c8STreehugger Robot     if (tid == 0)
16*7c3d14c8STreehugger Robot       idx = kMutex - idx - 1;
17*7c3d14c8STreehugger Robot     pthread_mutex_lock(&mtx[idx]);
18*7c3d14c8STreehugger Robot     pthread_mutex_unlock(&mtx[idx]);
19*7c3d14c8STreehugger Robot   }
20*7c3d14c8STreehugger Robot }
21*7c3d14c8STreehugger Robot 
bench()22*7c3d14c8STreehugger Robot void bench() {
23*7c3d14c8STreehugger Robot   for (int i = 0; i < kMutex; i++)
24*7c3d14c8STreehugger Robot     pthread_mutex_init(&mtx[i], 0);
25*7c3d14c8STreehugger Robot   start_thread_group(2, thread);
26*7c3d14c8STreehugger Robot }
27*7c3d14c8STreehugger Robot 
28*7c3d14c8STreehugger Robot // CHECK: DONE
29*7c3d14c8STreehugger Robot 
30