xref: /freebsd/tools/regression/pthread/unwind/catch_pthread_exit.cpp (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1 /* try to catch thread exiting, and rethrow the exception */
2 
3 #include <pthread.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 
7 static int caught;
8 
9 static void *
10 thr_routine(void *arg __unused)
11 {
12 	try {
13 		pthread_exit(NULL);
14 	} catch (...) {
15 		caught = 1;
16 		printf("thread exiting exception caught\n");
17 		/* rethrow */
18 		throw;
19 	}
20 }
21 
22 int
23 main()
24 {
25 	pthread_t td;
26 
27 	pthread_create(&td, NULL, thr_routine, NULL);
28 	pthread_join(td, NULL);
29 	if (caught)
30 		printf("OK\n");
31 	else
32 		printf("failure\n");
33 	return (0);
34 }
35