Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / bench_threads.cpp
blob1d0be21eb5c68b3173cdca9eaef492c28afd7fdb
1 // RUN: %clangxx_tsan %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s
4 // bench.h needs pthread barriers which are not available on OS X
5 // UNSUPPORTED: darwin
7 #include "bench.h"
9 void *nop_thread(void *arg) {
10 pthread_setname_np(pthread_self(), "nop_thread");
11 return nullptr;
14 void thread(int tid) {
15 for (int i = 0; i < bench_niter; i++) {
16 pthread_t th;
17 pthread_create(&th, nullptr, nop_thread, nullptr);
18 pthread_join(th, nullptr);
22 void bench() {
23 // Benchmark thread creation/joining in presence of a large number
24 // of threads (both alive and already joined).
25 printf("starting transient threads...\n");
26 for (int i = 0; i < 200; i++) {
27 const int kBatch = 100;
28 pthread_t th[kBatch];
29 for (int j = 0; j < kBatch; j++)
30 pthread_create(&th[j], nullptr, nop_thread, nullptr);
31 for (int j = 0; j < kBatch; j++)
32 pthread_join(th[j], nullptr);
34 printf("starting persistent threads...\n");
35 const int kLiveThreads = 2000;
36 pthread_t th[kLiveThreads];
37 for (int j = 0; j < kLiveThreads; j++)
38 pthread_create(&th[j], nullptr, nop_thread, nullptr);
39 printf("starting benchmark threads...\n");
40 start_thread_group(bench_nthread, thread);
41 for (int j = 0; j < kLiveThreads; j++)
42 pthread_join(th[j], nullptr);
45 // CHECK: DONE