Usually, parent thread who creates child thread, wants to get execution result (return value) of child thread.

For this, pthread_join() is used.

In most cases, pthread_create() / pthread_join() are used like a kind of pair.

So, habitually, developer tends to ignoring about detaching child thread.


But, in some cases, parent thread doesn't care about the result of child thread, and pthread_join() is not used.

In this case, child thread should be detached from parent thread to say that "parent thread doesn't care about the result".

Why this is required?

To pass return value of child thread, some  memory should be used to store result until it is consumed.

So, detaching means avoiding keep that memory.


In POSIX thread, there are two ways for detaching thread.

one is using pthread_detach() function, and the other is using PTHREAD_CREATE_DETACHED attribute at pthread_create().


Always keep in mind that child thread keep some amount of memory to pass it's return value to parent.


Process version of this case is "Zombie Process". See this post for details.

+ Recent posts