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