Sending a uncaught signal to a thread to terminate it is not recommended should be avoided, as it kills the entire process as opposed to killing just the individual thread.
...
Code Block | ||
---|---|---|
| ||
int main(int argc, char* argv[]){ pthread_t thread; pthread_create(&thread, NULL, func, 0); pthread_kill(thread, SIGKILL); /* May run a few more lines until the signal kills the process */ return 0; } void func(void *foo){ /* Execution of thread */ } |
...
Code Block | ||
---|---|---|
| ||
int main(int argc, char* argv[]){ pthread_t thread; pthread_create(&thread, NULL, func, (void*)0); sleep(1); pthread_cancel(thread); /* Continues */ return 0; } void func(void *foo){ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); /* Execution of thread */ } |
...