• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include "test.h"
3 
4 int Global;
5 int WTFGlobal;
6 
7 extern "C" {
8 void AnnotateBenignRaceSized(const char *f, int l,
9                              void *mem, unsigned int size, const char *desc);
10 void WTFAnnotateBenignRaceSized(const char *f, int l,
11                                 void *mem, unsigned int size,
12                                 const char *desc);
13 }
14 
15 
Thread(void * x)16 void *Thread(void *x) {
17   Global = 42;
18   WTFGlobal = 142;
19   barrier_wait(&barrier);
20   return 0;
21 }
22 
main()23 int main() {
24   barrier_init(&barrier, 2);
25   AnnotateBenignRaceSized(__FILE__, __LINE__,
26                           &Global, sizeof(Global), "Race on Global");
27   WTFAnnotateBenignRaceSized(__FILE__, __LINE__,
28                              &WTFGlobal, sizeof(WTFGlobal),
29                              "Race on WTFGlobal");
30   pthread_t t;
31   pthread_create(&t, 0, Thread, 0);
32   barrier_wait(&barrier);
33   Global = 43;
34   WTFGlobal = 143;
35   pthread_join(t, 0);
36   fprintf(stderr, "OK\n");
37 }
38 
39 // CHECK-NOT: WARNING: ThreadSanitizer: data race
40