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