Debian Codegraph @

gcc/testsuite/g++.dg/tls/thread_local4.C

raw
1 // Test for cleanups with pthread_cancel.
2
3 // { dg-do run }
4 // { dg-require-effective-target c++11 }
5 // { dg-require-effective-target tls_runtime }
6 // { dg-require-effective-target pthread }
7 // { dg-require-effective-target non_bionic }
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() { ++d; }
20 };
21
22 void f()
23 {
24 thread_local A a;
25 }
26
27 void *thread_main(void *)
28 {
29 f(); f(); f();
30 while (true)
31 {
32 pthread_testcancel();
33 sleep (1);
34 }
35 }
36
37 int main()
38 {
39 pthread_t thread;
40 pthread_create (&thread, 0, thread_main, 0);
41 pthread_cancel(thread);
42 pthread_join(thread, 0);
43 pthread_create (&thread, 0, thread_main, 0);
44 pthread_cancel(thread);
45 pthread_join(thread, 0);
46
47 if (c != 2 || d != 2)
48 __builtin_abort();
49 }