]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - tools/regression/pthread/unwind/catch_pthread_exit.cpp
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / tools / regression / pthread / unwind / catch_pthread_exit.cpp
1 /* $FreeBSD$ */
2 /* try to catch thread exiting, and rethrow the exception */
3
4 #include <pthread.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7
8 int caught;
9
10 void *
11 thr_routine(void *arg)
12 {
13         try {
14                 pthread_exit(NULL);
15         } catch (...) {
16                 caught = 1;
17                 printf("thread exiting exception caught\n");
18                 /* rethrow */
19                 throw;
20         }
21 }
22
23 int
24 main()
25 {
26         pthread_t td;
27
28         pthread_create(&td, NULL, thr_routine, NULL);
29         pthread_join(td, NULL);
30         if (caught)
31                 printf("OK\n");
32         else
33                 printf("failure\n");
34         return (0);
35 }