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-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 { AA19 A() { ++c; } ~AA20 ~A() { ++d; } 21 }; 22 23 thread_local A a; 24 thread_main(void *)25void *thread_main(void *) 26 { 27 A *ap = &a; 28 while (true) 29 { 30 pthread_testcancel(); 31 sleep (1); 32 } 33 } 34 main()35int main() 36 { 37 pthread_t thread; 38 pthread_create (&thread, 0, thread_main, 0); 39 pthread_cancel(thread); 40 pthread_join(thread, 0); 41 pthread_create (&thread, 0, thread_main, 0); 42 pthread_cancel(thread); 43 pthread_join(thread, 0); 44 45 if (c != 2 || d != 2) 46 __builtin_abort(); 47 } 48