Path: blob/main/tools/regression/pthread/unwind/cond_wait_cancel2.cpp
39553 views
/*1*2* Test stack unwinding for mixed pthread_cleanup_push/pop and C++3* object, both should work together.4*5*/67#include <pthread.h>8#include <stdio.h>9#include <semaphore.h>10#include <unistd.h>1112#include "Test.cpp"1314static pthread_mutex_t mtx;15static pthread_cond_t cv;1617static void f()18{19Test t;2021pthread_mutex_lock(&mtx);22pthread_cond_wait(&cv, &mtx);23pthread_mutex_unlock(&mtx);24printf("Bug, thread shouldn't be here.\n");25}2627static void g()28{29f();30}3132static void *33thr(void *arg __unused)34{35pthread_cleanup_push(cleanup_handler, NULL);36g();37pthread_cleanup_pop(0);38return (0);39}4041int42main()43{44pthread_t td;4546pthread_mutex_init(&mtx, NULL);47pthread_cond_init(&cv, NULL);48pthread_create(&td, NULL, thr, NULL);49sleep(1);50pthread_cancel(td);51pthread_join(td, NULL);52check_destruct2();53return (0);54}555657