Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

29. Threads: Introduction > Joining with a Terminated Thread

Joining with a Terminated Thread

The pthread_join() function waits for the thread identified by thread to terminate. (If that thread has already terminated, pthread_join() returns immediately.) This operation is termed joining.

include <pthread.h>

int pthread_join(pthread_t thread, void **retval);

Note

Returns 0 on success, or a positive error number on error

If retval is a non-NULL pointer, then it receives a copy of the terminated thread’s return value—that is, the value that was specified when the thread performed a return or called pthread_exit().

Calling pthread_join() for a thread ID that has been previously joined can lead to unpredictable behavior; for example, it might instead join with a thread created later that happened to reuse the same thread ID.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint