summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/tls/thread_local6g.C
blob: d357ca4fa1f8bb61c8b1a7bc22e924e668f81173 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Test for cleanups in the main thread without -pthread.

// { dg-do run { target c++11 } }
// { dg-add-options tls }
// { dg-require-effective-target unwrapped }
// { dg-require-effective-target tls_runtime }
// { dg-require-cxa-atexit "" }

extern "C" void _exit (int);

int c;
struct A
{
  A() { ++c; }
  ~A() { if (c == 1) _exit(0); }
};

thread_local A a;

void *thread_main(void *)
{
  A* ap = &a;
  return 0;
}

int main()
{
  thread_main(0);

  // The dtor for a in the main thread is run after main exits, so we
  // return 1 now and override the return value with _exit above.
  return 1;
}