...
This code instead uses the pthread_cancel() to terminate the thread. The thread continues to run until it reaches a cancellation point. See the second referenced article for a list of functions that are cancellation points. If the cancellation type is set to asynchronous, the thread is terminated immediately. However, POSIX only requires the pthread_cancel(), pthread_setcancelstate(), and pthread_setcanceltype() functions to be asynchronous async-cancel safe. An implementation application that calls other POSIX functions with asynchronous cancellation enabled is non-conforming.
| Code Block | ||
|---|---|---|
| ||
int main(void){
pthread_t thread;
pthread_create(&thread, NULL, func, (void*)0);
pthread_cancel(thread);
/* Continues */
return 0;
}
void func(void *foo){
/* Execution of thread */
}
|
...