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 pthread_mutex_t mtx; 10*7c3d14c8STreehugger Robot pthread_cond_t cv; 11*7c3d14c8STreehugger Robot int x; 12*7c3d14c8STreehugger Robot thread(int tid)13*7c3d14c8STreehugger Robotvoid thread(int tid) { 14*7c3d14c8STreehugger Robot for (int i = 0; i < bench_niter; i++) { 15*7c3d14c8STreehugger Robot pthread_mutex_lock(&mtx); 16*7c3d14c8STreehugger Robot while (x != i * 2 + tid) 17*7c3d14c8STreehugger Robot pthread_cond_wait(&cv, &mtx); 18*7c3d14c8STreehugger Robot x++; 19*7c3d14c8STreehugger Robot pthread_cond_signal(&cv); 20*7c3d14c8STreehugger Robot pthread_mutex_unlock(&mtx); 21*7c3d14c8STreehugger Robot } 22*7c3d14c8STreehugger Robot } 23*7c3d14c8STreehugger Robot bench()24*7c3d14c8STreehugger Robotvoid bench() { 25*7c3d14c8STreehugger Robot pthread_mutex_init(&mtx, 0); 26*7c3d14c8STreehugger Robot pthread_cond_init(&cv, 0); 27*7c3d14c8STreehugger Robot start_thread_group(2, thread); 28*7c3d14c8STreehugger Robot } 29*7c3d14c8STreehugger Robot 30*7c3d14c8STreehugger Robot // CHECK: DONE 31*7c3d14c8STreehugger Robot 32