I have the following code:
#include
#include
#include
pthread_t test_thread;
void *thread_test_run (void *v)
This is how I implement some sort of what you want in my utilite https://github.com/seriyps/wrk/commit/1d3c5dda0d46f0e567f3bae793bb3ae182de9438
static thread *threads;
int main(....){
...
sigint_action.sa_handler = &sig_handler;
sigemptyset (&sigint_action.sa_mask);
/* reset handler in case when pthread_cancel didn't stop
threads for some reason */
sigint_action.sa_flags = SA_RESETHAND;
sigaction(SIGTERM, &sigint_action, NULL);
...
}
static void sig_handler(int signum) {
printf("interrupted\n");
for (uint64_t i = 0; i < cfg.threads; i++) {
if(pthread_cancel(threads[i].thread)) exit(1);
}
}