Daily bump.
[official-gcc.git] / gcc / testsuite / g++.dg / tls / thread_local5.C
blob61fea722dc26fd71c85771557aecfbaa9ab287f4
1 // Test for cleanups in the main thread, too.
3 // { dg-do run }
4 // { dg-require-effective-target c++11 }
5 // { dg-require-effective-target unwrapped }
6 // { dg-require-effective-target tls_runtime }
7 // { dg-require-effective-target pthread }
8 // { dg-options -pthread }
9 // { dg-add-options tls }
11 #include <pthread.h>
12 #include <unistd.h>
14 int c;
15 int d;
16 struct A
18   A() { ++c; }
19   ~A() {
20     if (++d == 3)
21       _exit (0);
22   }
25 void f()
27   thread_local A a;
30 void *thread_main(void *)
32   f(); f(); f();
33   return 0;
36 int main()
38   pthread_t thread;
39   thread_main(0);
40   pthread_create (&thread, 0, thread_main, 0);
41   pthread_join(thread, 0);
42   pthread_create (&thread, 0, thread_main, 0);
43   pthread_join(thread, 0);
45   // The dtor for a in the main thread is run after main exits, so we
46   // return 1 now and override the return value with _exit above.
47   if (c != 3 || d != 2)
48     __builtin_abort();
49   return 1;