pthread_detach |
Prototype: |
#include <pthread.h>
int pthread_detach(thread_t tchild);
|
General Description: |
Detaches tchild thread from the parent. Normally you need to join or wait for every process and thread. This call lets you create several threads and ignore them. This is the same as setting the thread's attribute upon creation. |
Return Value: |
A positive value if successful. If the thread-create call encountered any errors, the call returns a negative value and sets errno to the error. |
Parameters |
tchild |
The child thread to detach. |
Possible Errors |
ESRCH |
|
|
No thread could be found corresponding to that specified by tchild. |
EINVAL |
The tchild thread has been detached. |
EINVAL |
Another thread is already waiting on termination of tchild. |
EDEADLK |
The tchild argument refers to the calling thread. |
Examples |
void* child(void *arg)
{
/**** Do something! ****/
pthread_exit(arg); /* terminate and return arg */
}
int main()
{ pthread_t tchild;
if ( pthread_create(&tchild, 0, child, 0) < 0 )
perror("Can't create thread!");
else
pthread_detach(tchild);
/**** Do something! ****/
}
(c)Locking
|