Remove not needed __builtin_expect due to malloc predictor.
[official-gcc.git] / gcc / testsuite / g++.dg / tls / thread_local5g.C
blob596bbbe542fecc4f59aa968d4c88b4deaf914de7
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-require-cxa-atexit "" }
9 // { dg-options -pthread }
10 // { dg-add-options tls }
12 #include <pthread.h>
13 #include <unistd.h>
15 int c;
16 int d;
17 struct A
19   A() { ++c; }
20   ~A() {
21     if (++d == 3)
22       _exit (0);
23   }
26 thread_local A a;
28 void *thread_main(void *)
30   A* ap = &a;
31   return 0;
34 int main()
36   pthread_t thread;
37   thread_main(0);
38   pthread_create (&thread, 0, thread_main, 0);
39   pthread_join(thread, 0);
40   pthread_create (&thread, 0, thread_main, 0);
41   pthread_join(thread, 0);
43   // The dtor for a in the main thread is run after main exits, so we
44   // return 1 now and override the return value with _exit above.
45   if (c != 3 || d != 2)
46     __builtin_abort();
47   return 1;