| 1 |
// Test for cleanups in the main thread without -pthread. |
| 2 |
|
| 3 |
// { dg-do run { target c++11 } } |
| 4 |
// { dg-add-options tls } |
| 5 |
// { dg-require-effective-target unwrapped } |
| 6 |
// { dg-require-effective-target tls_runtime } |
| 7 |
// { dg-require-cxa-atexit "" } |
| 8 |
|
| 9 |
extern "C" void _exit (int); |
| 10 |
|
| 11 |
int c; |
| 12 |
struct A |
| 13 |
{ |
| 14 |
A() { ++c; } |
| 15 |
~A() { if (c == 1) _exit(0); } |
| 16 |
}; |
| 17 |
|
| 18 |
thread_local A a; |
| 19 |
|
| 20 |
void *thread_main(void *) |
| 21 |
{ |
| 22 |
A* ap = &a; |
| 23 |
return 0; |
| 24 |
} |
| 25 |
|
| 26 |
int main() |
| 27 |
{ |
| 28 |
thread_main(0); |
| 29 |
|
| 30 |
// The dtor for a in the main thread is run after main exits, so we |
| 31 |
// return 1 now and override the return value with _exit above. |
| 32 |
return 1; |
| 33 |
} |