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-options -pthread }
|
|
9 // { dg-add-options tls }
|
|
10
|
|
11 #include <pthread.h>
|
|
12 #include <unistd.h>
|
|
13
|
|
14 int c;
|
|
15 int d;
|
|
16 struct A
|
|
17 {
|
|
18 A() { ++c; }
|
|
19 ~A() {
|
|
20 if (++d == 3)
|
|
21 _exit (0);
|
|
22 }
|
|
23 };
|
|
24
|
|
25 void f()
|
|
26 {
|
|
27 thread_local A a;
|
|
28 }
|
|
29
|
|
30 void *thread_main(void *)
|
|
31 {
|
|
32 f(); f(); f();
|
131
|
33 return 0;
|
111
|
34 }
|
|
35
|
|
36 int main()
|
|
37 {
|
|
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);
|
|
44
|
|
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;
|
|
50 }
|