003 Linux System ProgrammingIssues, queries and suggestions related to Linux, Linux Programming, IPC, Interprocess Communication, Synchronization, Semaphore, System Programming, Linux Software Development. » 003.11.POSIX-Threads
pthread_join() function is used by one thread to wait for another thread to finish execution.
when pthread_join is executes the calling thread goes into block states until created thread terminates and executes pthread_exit () call,the created thread then resumes execution and retrieve the exit status of creted thread.
purpose of pthread_join()
1)synchronization:
some situation where one thread need to wait for another thread to finish before it can proceed it is where pthread_join() is needed.
2)Resource cleanup:
when thread finish execution some resource are still held by OS such as stack ,thread control box .these resource are not automatically release unless threads is deattach thread .so if thread is joinable it must be join by another thread to finish and clean up the resource acquired by thread.
3)Return value:
pthread_join() allow calling thread to retrieve the return value of created thread