pthread_exit

Terminates the calling thread.

Library:LibC
Classification:POSIX
Service:Threads

Syntax

  #include <pthread.h>
   
  void pthread_exit (
     void   *status);
  

Parameters

status

(IN) Points to an application-defined exit value for the thread. This can be NULL.

Remarks

When an application thread calls pthread_exit, the thread is terminated. If it was created as a joinable thread, its exit value is returned to the sibling thread that successfully performs the pthread_join operation on this departing thread.

When a detached thread exits, it cleans up after itself automatically. However, when a joinable thread exists and a thread is not already waiting to join the exiting thread, the system maintains sufficient state to support subsequent calls to pthread_join. If you do not call pthread_join on an exited joinable thread, system resources are held up unnecessarily.

When the process is terminated, all resources allocated to the process are freed. If the departing thread is the last application thread in the process, pthread_exit terminates the containing process. When the thread executing main calls pthread_exit, the process is not torn down unless this thread is also the last application thread.

See Also