1// RUN: %clangxx_tsan %s -o %t
2// RUN: %run %t 2>&1 | FileCheck %s
3
4#include "bench.h"
5
6pthread_mutex_t mtx;
7pthread_cond_t cv;
8int x;
9
10void thread(int tid) {
11  for (int i = 0; i < bench_niter; i++) {
12    pthread_mutex_lock(&mtx);
13    while (x != i * 2 + tid)
14      pthread_cond_wait(&cv, &mtx);
15    x++;
16    pthread_cond_signal(&cv);
17    pthread_mutex_unlock(&mtx);
18  }
19}
20
21void bench() {
22  pthread_mutex_init(&mtx, 0);
23  pthread_cond_init(&cv, 0);
24  start_thread_group(2, thread);
25}
26
27// CHECK: DONE
28
29