Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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 in most cases it is not safe to do so, and should be generally avoided. However, POSIX only requires the pthread_cancel(), pthread_setcancelstate(), and pthread_setcanceltype() functions to be asynchronous safe. An implementation that calls other POSIX functions with asynchronous cancellation is non-conforming.

Code Block
bgColor#ccccff
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 */
}

...

Wiki Markup
\[[OpenBSD|AA. References#OpenBSD]\] [{{signal()}} Man Page|http://www.openbsd.org/cgi-bin/man.cgi?query=signal]
[http://www.mkssoftware.com/docs/man3/pthread_cancel.3.asp]
[http://www.opengroup.org/onlinepubs/007908799/xsh/threads.html]