Pthread_detach ()-mark a thread as detached to reclaim its resources when it terminates
Synopsis
# Include <Pthread. h>
Int pthread_detach ( Pthread_t thread );
Parameters
-
Thread
-
Thread whose resources are to be reclaimed immediately when it terminates.
Description
Pthread_detach ()Is used to detach the threadThread. WhenThreadTerminates, its resources will automatically be reclaimed by the system. IfThreadHas already terminated,Pthread_detach ()Causes the resourcesThreadTo be reclaimed by the system.
Pthread_detach ()Does not causeThreadTo terminate.
Once a detached thread has terminated, its resources, including the thread ID, may be reused by the system. The return status of a detached thread is lost when the thread terminates.
Calling this function multiple times for the same thread results in undefined behavior.
Return Value
Upon successful completion,Pthread_detach ()Returns zero. Otherwise, an error number is returned to indicate the error (ErrnoVariable is not set ).
Errors
If any of the following occur,Pthread_detach ()Function returns the corresponding error number:
- [Einval]
-
ThreadDoes not refer to a joinable thread.
- [Esrch]
-
No thread cocould be found correspondingThread.
Author
Pthread_detach ()Was derived from the ieee posix p1003.1c standard.