Debian Codegraph @

gcc/testsuite/g++.dg/tls/thread_local3.C

raw
1 // { dg-do run }
2 // { dg-require-effective-target c++11 }
3 // { dg-require-effective-target tls_runtime }
4 // { dg-require-effective-target pthread }
5 // { dg-options -pthread }
6 // { dg-add-options tls }
7
8 int c;
9 int d;
10 struct A
11 {
12 A() { ++c; }
13 ~A() { ++d; }
14 };
15
16 void f()
17 {
18 thread_local A a;
19 }
20
21 void *thread_main(void *)
22 {
23 f(); f(); f();
24 return 0;
25 }
26
27 #include <pthread.h>
28
29 int main()
30 {
31 pthread_t thread;
32 pthread_create (&thread, 0, thread_main, 0);
33 pthread_join(thread, 0);
34 pthread_create (&thread, 0, thread_main, 0);
35 pthread_join(thread, 0);
36
37 if (c != 2 || d != 2)
38 __builtin_abort();
39 }