1 #include <pthread.h>
2 #include <stdio.h>
3 #include <unistd.h>
4 
5 int Global;
6 int WTFGlobal;
7 
8 extern "C" {
9 void AnnotateBenignRaceSized(const char *f, int l,
10                              void *mem, unsigned int size, const char *desc);
11 void WTFAnnotateBenignRaceSized(const char *f, int l,
12                                 void *mem, unsigned int size,
13                                 const char *desc);
14 }
15 
16 
Thread(void * x)17 void *Thread(void *x) {
18   Global = 42;
19   WTFGlobal = 142;
20   return 0;
21 }
22 
main()23 int main() {
24   AnnotateBenignRaceSized(__FILE__, __LINE__,
25                           &Global, sizeof(Global), "Race on Global");
26   WTFAnnotateBenignRaceSized(__FILE__, __LINE__,
27                              &WTFGlobal, sizeof(WTFGlobal),
28                              "Race on WTFGlobal");
29   pthread_t t;
30   pthread_create(&t, 0, Thread, 0);
31   sleep(1);
32   Global = 43;
33   WTFGlobal = 143;
34   pthread_join(t, 0);
35   fprintf(stderr, "OK\n");
36 }
37 
38 /* { dg-prune-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */
39