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