1/* 2 * 3 * Test stack unwinding for mixed pthread_cleanup_push/pop and C++ 4 * object, both should work together. 5 * 6 */ 7 8#include <pthread.h> 9#include <stdio.h> 10#include <semaphore.h> 11#include <unistd.h> 12 13#include "Test.cpp" 14 15static pthread_mutex_t mtx; 16static pthread_cond_t cv; 17 18static void f() 19{ 20 Test t; 21 22 pthread_mutex_lock(&mtx); 23 pthread_cond_wait(&cv, &mtx); 24 pthread_mutex_unlock(&mtx); 25 printf("Bug, thread shouldn't be here.\n"); 26} 27 28static void g() 29{ 30 f(); 31} 32 33static void * 34thr(void *arg __unused) 35{ 36 pthread_cleanup_push(cleanup_handler, NULL); 37 g(); 38 pthread_cleanup_pop(0); 39 return (0); 40} 41 42int 43main() 44{ 45 pthread_t td; 46 47 pthread_mutex_init(&mtx, NULL); 48 pthread_cond_init(&cv, NULL); 49 pthread_create(&td, NULL, thr, NULL); 50 sleep(1); 51 pthread_cancel(td); 52 pthread_join(td, NULL); 53 check_destruct2(); 54 return (0); 55} 56