xref: /aosp_15_r20/external/compiler-rt/test/tsan/static_init1.cc (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2*7c3d14c8STreehugger Robot #include <pthread.h>
3*7c3d14c8STreehugger Robot #include <stdlib.h>
4*7c3d14c8STreehugger Robot #include <stdio.h>
5*7c3d14c8STreehugger Robot 
6*7c3d14c8STreehugger Robot struct P {
7*7c3d14c8STreehugger Robot   int x;
8*7c3d14c8STreehugger Robot   int y;
9*7c3d14c8STreehugger Robot };
10*7c3d14c8STreehugger Robot 
Thread(void * x)11*7c3d14c8STreehugger Robot void *Thread(void *x) {
12*7c3d14c8STreehugger Robot   static P p = {rand(), rand()};
13*7c3d14c8STreehugger Robot   if (p.x > RAND_MAX || p.y > RAND_MAX)
14*7c3d14c8STreehugger Robot     exit(1);
15*7c3d14c8STreehugger Robot   return 0;
16*7c3d14c8STreehugger Robot }
17*7c3d14c8STreehugger Robot 
main()18*7c3d14c8STreehugger Robot int main() {
19*7c3d14c8STreehugger Robot   pthread_t t[2];
20*7c3d14c8STreehugger Robot   pthread_create(&t[0], 0, Thread, 0);
21*7c3d14c8STreehugger Robot   pthread_create(&t[1], 0, Thread, 0);
22*7c3d14c8STreehugger Robot   pthread_join(t[0], 0);
23*7c3d14c8STreehugger Robot   pthread_join(t[1], 0);
24*7c3d14c8STreehugger Robot   fprintf(stderr, "PASS\n");
25*7c3d14c8STreehugger Robot }
26*7c3d14c8STreehugger Robot 
27*7c3d14c8STreehugger Robot // CHECK-NOT: WARNING: ThreadSanitizer: data race
28