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 // aarch64 fails with: 8 // CHECK failed: tsan_rtl.cpp:327 "((addr + size)) <= ((TraceMemEnd()))" 9 // TODO: try to re-enable when D112603 is landed. 10 // XFAIL: aarch64 11 12 #include "bench.h" 13 14 void *nop_thread(void *arg) { 15 pthread_setname_np(pthread_self(), "nop_thread"); 16 return nullptr; 17 } 18 19 void thread(int tid) { 20 for (int i = 0; i < bench_niter; i++) { 21 pthread_t th; 22 pthread_create(&th, nullptr, nop_thread, nullptr); 23 pthread_join(th, nullptr); 24 } 25 } 26 27 void bench() { 28 // Benchmark thread creation/joining in presence of a large number 29 // of threads (both alive and already joined). 30 printf("starting transient threads...\n"); 31 for (int i = 0; i < 200; i++) { 32 const int kBatch = 100; 33 pthread_t th[kBatch]; 34 for (int j = 0; j < kBatch; j++) 35 pthread_create(&th[j], nullptr, nop_thread, nullptr); 36 for (int j = 0; j < kBatch; j++) 37 pthread_join(th[j], nullptr); 38 } 39 printf("starting persistent threads...\n"); 40 const int kLiveThreads = 2000; 41 pthread_t th[kLiveThreads]; 42 for (int j = 0; j < kLiveThreads; j++) 43 pthread_create(&th[j], nullptr, nop_thread, nullptr); 44 printf("starting benchmark threads...\n"); 45 start_thread_group(bench_nthread, thread); 46 for (int j = 0; j < kLiveThreads; j++) 47 pthread_join(th[j], nullptr); 48 } 49 50 // CHECK: DONE 51