blob: 58aa86a787d32b8686a9c6ef1621340c0ced21da [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// RUN: %clangxx_tsan %s -o %t
2// RUN: %run %t 2>&1 | FileCheck %s
3
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08004// bench.h needs pthread barriers which are not available on OS X
5// UNSUPPORTED: darwin
6
Stephen Hines2d1fdb22014-05-28 23:58:16 -07007#include "bench.h"
8
9pthread_mutex_t mtx;
10pthread_cond_t cv;
11int x;
12
13void thread(int tid) {
14 for (int i = 0; i < bench_niter; i++) {
15 pthread_mutex_lock(&mtx);
16 while (x != i * 2 + tid)
17 pthread_cond_wait(&cv, &mtx);
18 x++;
19 pthread_cond_signal(&cv);
20 pthread_mutex_unlock(&mtx);
21 }
22}
23
24void bench() {
25 pthread_mutex_init(&mtx, 0);
26 pthread_cond_init(&cv, 0);
27 start_thread_group(2, thread);
28}
29
30// CHECK: DONE
31