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
9 void *nop_thread(void *arg
) {
10 pthread_setname_np(pthread_self(), "nop_thread");
14 void thread(int tid
) {
15 for (int i
= 0; i
< bench_niter
; i
++) {
17 pthread_create(&th
, nullptr, nop_thread
, nullptr);
18 pthread_join(th
, nullptr);
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;
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);