pthread_detach

Converts a joinable thread to a detached (non-joinable) thread.

Library:LibC
Classification:POSIX
Service:Threads

Syntax

  #include <pthread.h>
   
  int pthread_detach (
     pthread_t   thread);
  

Parameters

thread

(IN) Specifies the ID of the thread to convert to a detached thread.

Return Values

If successful, returns 0; otherwise, returns a nonzero error code:

Decimal

Constant

Description

9

EINVAL

The target thread is not a joinable thread.

77

ESRCH

The specified thread ID is invalid; it might not exist.

Remarks

If successful, pthread_detach converts the joinable thread specified by the thread parameter to a detached thread. Such a thread can no longer be joined using the pthread_join function.

If a thread has already called pthread_join for the thread being detached, the thread returns from pthread_join with an error indicating that the thread being joined was not joinable.If the thread being detached has already exited and is waiting for a join operation, it will be cleaned up immediately. The thread cannot be subsequently joined using pthread_join.

The pthread_detach function can be called by a thread for itself, but thread ID has to be derived by calling pthread_self.

See Also