brintos

brintos / llvm-project-archived public Read only

0
0
Text · 589 B · e7fa05e Raw
30 lines · cpp
1// RUN: %clangxx_tsan %s -o %t2// RUN: %run %t 2>&1 | FileCheck %s3 4// bench.h needs pthread barriers which are not available on OS X5// UNSUPPORTED: darwin6 7#include "bench.h"8 9const int kMutex = 10;10pthread_mutex_t mtx[kMutex];11 12void thread(int tid) {13  for (int i = 0; i < bench_niter; i++) {14    int idx = (i % kMutex);15    if (tid == 0)16      idx = kMutex - idx - 1;17    pthread_mutex_lock(&mtx[idx]);18    pthread_mutex_unlock(&mtx[idx]);19  }20}21 22void bench() {23  for (int i = 0; i < kMutex; i++)24    pthread_mutex_init(&mtx[i], 0);25  start_thread_group(2, thread);26}27 28// CHECK: DONE29 30