opnsense-src/tools/regression/pthread/unwind/catch_pthread_exit.cpp
Ed Maste ef135466f8 Clean up warnings in pthread tests
I intend to move these into lib/libthr/tests/ and connect to kyua.  This
is a first step to address warnings emitted when building using standard
make infrastructure.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D34306
2022-02-16 16:28:31 -05:00

35 lines
521 B
C++

/* $FreeBSD$ */
/* try to catch thread exiting, and rethrow the exception */
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
static int caught;
static void *
thr_routine(void *arg __unused)
{
try {
pthread_exit(NULL);
} catch (...) {
caught = 1;
printf("thread exiting exception caught\n");
/* rethrow */
throw;
}
}
int
main()
{
pthread_t td;
pthread_create(&td, NULL, thr_routine, NULL);
pthread_join(td, NULL);
if (caught)
printf("OK\n");
else
printf("failure\n");
return (0);
}