brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 1e97358 Raw
58 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && %deflake %run %t | FileCheck %s2// RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && %deflake %run %t | FileCheck %s3#include "test.h"4 5volatile int X;6volatile int N;7void (*volatile F)();8 9static void foo() {10  if (--N == 0)11    X = 42;12  else13    F();14}15 16void *Thread(void *p) {17#ifdef ORDER118  barrier_wait(&barrier);19#endif20  F();21#ifdef ORDER222  barrier_wait(&barrier);23#endif24  return 0;25}26 27static size_t RoundUp(size_t n, size_t to) {28  return ((n + to - 1) / to) * to;29}30 31int main() {32  barrier_init(&barrier, 2);33  N = 50000;34  F = foo;35  pthread_t t;36  pthread_attr_t a;37  pthread_attr_init(&a);38  size_t stack_size = N * 256 + (1 << 20);39  stack_size = RoundUp(stack_size, 0x10000);  // round the stack size to 64k40  int ret = pthread_attr_setstacksize(&a, stack_size);41  if (ret) abort();42  pthread_create(&t, &a, Thread, 0);43#ifdef ORDER244  barrier_wait(&barrier);45#endif46  X = 43;47#ifdef ORDER148  barrier_wait(&barrier);49#endif50 51  pthread_join(t, 0);52}53 54// CHECK: WARNING: ThreadSanitizer: data race55// CHECK:    #100 foo56// We must output sufficiently large stack (at least 100 frames)57 58