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_exit() function is used to explicitly terminate the thread in multi threaded program.
it provide a way for threads to signal that i has completed its work and is ready to be cleanup by operating system.
purpose of pthread_exit() :
(1)To return a value from one thread:
when a thread finished its task and need to return value to another thread.pthread_exit is used .
(2)Avoiding abnormal termination:
If threads return from function abnormally it leads to resource leak so pthreads_exit() ensures threads terminates clearly.
(3)Main Threads termination:
If main threads return from main function the process will terminates and all threads in that process will abruptly terminates calling pthread_exit() in main prevent this .The process will remain alive as long as there are active thread.