How to Detaching a Thread in operating system

6:51 AM
The function pthread_detach() is an alternative to pthread_join() to reclaim storage for a thread that is created with a detachstate attribute set to PTHREAD_CREATE_JOINABLE. It is prototyped by:


int pthread\_detach(thread\_t tid);


A simple example of calling this fucntion to detatch a thread is given by:


#include
pthread_t tid;
int ret;
/* detach thread tid */
ret = pthread_detach(tid);


The pthread_detach() function is used to indicate to the implementation that storage for the thread tid can be reclaimed when the thread terminates. If tid has not terminated, pthread_detach() does not cause it to terminate. The effect of multiple pthread_detach() calls on the same target thread is unspecified.

0 Comments