best way for destroy mutex and cond (resource free)
Hello everyone, please see the pseudo-code below:
static void *func1(void *arg) {
while(1){
}
}
static void *func2(void *arg) {
while(1){
}
}
int main()
{
pthread_t t1, t2;
pthread_create(&t1, NULL, func1, NULL);
pthread_create(&t2, NULL, func2, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
return 0;
}
If the two threads above use a mutex (lock and unlock) and a condition variable, and I close the process with Ctrl+C (SIGINT), then if I write a simple signal handler to destroy the mutex and cond, it shows UB (undefined behavior). Now, how can I write a safe signal handler? How can I unlock and destroy safely?