brintos

brintos / llvm-project-archived public Read only

0
0
Text · 615 B · 6f293e3 Raw
29 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s2#include "test.h"3 4int *g;5 6void *Thread(void *a) {7  int *p = 0;8  while ((p = __atomic_load_n(&g, __ATOMIC_RELAXED)) == 0)9    usleep(100);  // spin-wait10  *p = 42;11  return 0;12}13 14int main() {15  pthread_t t;16  pthread_create(&t, 0, Thread, 0);17  AnnotateIgnoreWritesBegin(__FILE__, __LINE__);18  int *p = new int(0);19  AnnotateIgnoreWritesEnd(__FILE__, __LINE__);20  __atomic_store_n(&g, p, __ATOMIC_RELAXED);21  pthread_join(t, 0);22  delete p;23  fprintf(stderr, "OK\n");24  return 0;25}26 27// CHECK-NOT: WARNING: ThreadSanitizer: data race28// CHECK: OK29