111
|
1 // Test for cleanups in the main thread, too.
|
|
2
|
|
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 }
|
|
11
|
|
12 #include <pthread.h>
|
|
13 #include <unistd.h>
|
|
14
|
|
15 int c;
|
|
16 int d;
|
|
17 struct A
|
|
18 {
|
|
19 A() { ++c; }
|
|
20 ~A() {
|
|
21 if (++d == 3)
|
|
22 _exit (0);
|
|
23 }
|
|
24 };
|
|
25
|
|
26 thread_local A a;
|
|
27
|
|
28 void *thread_main(void *)
|
|
29 {
|
|
30 A* ap = &a;
|
131
|
31 return 0;
|
111
|
32 }
|
|
33
|
|
34 int main()
|
|
35 {
|
|
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);
|
|
42
|
|
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;
|
|
48 }
|