summaryrefslogtreecommitdiff
path: root/test/tsan/bench_ten_mutexes.cc
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2014-03-24 14:32:59 +0000
committerDmitry Vyukov <dvyukov@google.com>2014-03-24 14:32:59 +0000
commitd491821dba7a2d73739d4c888d14eadd90471012 (patch)
treedff63d9a6e76cbd417c40dbb835d17f6bad410c1 /test/tsan/bench_ten_mutexes.cc
parent1e5d8befc4aea476f7d4d1f42b0a935d7e443a68 (diff)
tsan: add benchmarks for synchronization handling
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@204608 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/bench_ten_mutexes.cc')
-rw-r--r--test/tsan/bench_ten_mutexes.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/tsan/bench_ten_mutexes.cc b/test/tsan/bench_ten_mutexes.cc
new file mode 100644
index 000000000..994d2ac99
--- /dev/null
+++ b/test/tsan/bench_ten_mutexes.cc
@@ -0,0 +1,26 @@
+// RUN: %clangxx_tsan %s -o %t
+// RUN: %t 2>&1 | FileCheck %s
+
+#include "bench.h"
+
+const int kMutex = 10;
+pthread_mutex_t mtx[kMutex];
+
+void thread(int tid) {
+ for (int i = 0; i < bench_niter; i++) {
+ int idx = (i % kMutex);
+ if (tid == 0)
+ idx = kMutex - idx - 1;
+ pthread_mutex_lock(&mtx[idx]);
+ pthread_mutex_unlock(&mtx[idx]);
+ }
+}
+
+void bench() {
+ for (int i = 0; i < kMutex; i++)
+ pthread_mutex_init(&mtx[i], 0);
+ start_thread_group(2, thread);
+}
+
+// CHECK: DONE
+