llvm-project
30 строк · 591.0 Байт
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#include "bench.h"
8
9pthread_mutex_t mtx;
10pthread_cond_t cv;
11int x;
12
13void thread(int tid) {
14for (int i = 0; i < bench_niter; i++) {
15pthread_mutex_lock(&mtx);
16while (x != i * 2 + tid)
17pthread_cond_wait(&cv, &mtx);
18x++;
19pthread_cond_signal(&cv);
20pthread_mutex_unlock(&mtx);
21}
22}
23
24void bench() {
25pthread_mutex_init(&mtx, 0);
26pthread_cond_init(&cv, 0);
27start_thread_group(2, thread);
28}
29
30// CHECK: DONE
31
32