xref: /llvm-project/compiler-rt/test/nsan/Posix/tls_reuse.c (revision 52ae891036e3ab1f668eb103c46ca57257901c6b)
1 /// The static TLS block is reused among by threads. The shadow is cleared.
2 // RUN: %clang_nsan %s -o %t
3 // RUN: env NSAN_OPTIONS=halt_on_error=1,log2_max_relative_error=19 %run %t
4 
5 #include <pthread.h>
6 #include <stdio.h>
7 
8 __thread float x;
9 
10 static void *ThreadFn(void *a) {
11   long i = (long)a;
12   for (long j = i * 1000; j < (i + 1) * 1000; j++)
13     x += j;
14   printf("%f\n", x);
15   return 0;
16 }
17 
18 int main() {
19   pthread_t t;
20   for (long i = 0; i < 5; ++i) {
21     pthread_create(&t, 0, ThreadFn, (void *)i);
22     pthread_join(t, 0);
23   }
24 }
25