summaryrefslogtreecommitdiffstats
path: root/tools/regression/pthread/unwind/cond_wait_cancel2.cpp
blob: c781068918f11a61c3b501abac2073ddea905e10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * $FreeBSD$
 *
 * Test stack unwinding for mixed pthread_cleanup_push/pop and C++
 * object, both should work together.
 *
 */

#include <pthread.h>
#include <stdio.h>
#include <semaphore.h>
#include <unistd.h>

#include "Test.cpp"

pthread_mutex_t mtx;
pthread_cond_t cv;

void f()
{
	Test t;

	pthread_mutex_lock(&mtx);
	pthread_cond_wait(&cv, &mtx);
	pthread_mutex_unlock(&mtx);
	printf("Bug, thread shouldn't be here.\n");
}

void g()
{
	f();
}

void *
thr(void *arg)
{
	pthread_cleanup_push(cleanup_handler, NULL);
	g();
	pthread_cleanup_pop(0);
	return (0);
}

int
main()
{
	pthread_t td;

	pthread_mutex_init(&mtx, NULL);
	pthread_cond_init(&cv, NULL);
	pthread_create(&td, NULL, thr, NULL);
	sleep(1);
	pthread_cancel(td);
	pthread_join(td, NULL);
	check_destruct2();
	return (0);
}
OpenPOWER on IntegriCloud