xref: /freebsd/tools/regression/pthread/unwind/sem_wait_cancel.cpp (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1 /* $FreeBSD$ */
2 /* Test stack unwinding for libc's sem */
3 
4 #include <pthread.h>
5 #include <stdio.h>
6 #include <semaphore.h>
7 #include <unistd.h>
8 
9 #include "Test.cpp"
10 
11 sem_t sem;
12 
13 void *
14 thr(void *arg)
15 {
16 	Test t;
17 
18 	sem_wait(&sem);
19 	printf("Bug, thread shouldn't be here.\n");
20 	return (0);
21 }
22 
23 int
24 main()
25 {
26 	pthread_t td;
27 
28 	sem_init(&sem, 0, 0);
29 	pthread_create(&td, NULL, thr, NULL);
30 	sleep(1);
31 	pthread_cancel(td);
32 	pthread_join(td, NULL);
33 	check_destruct();
34 	return (0);
35 }
36