So guys, now let us discuss what are detached threads.
So the detached threads works exactly opposite to Joinable thread.
So let us suppose that you have a multi threaded program and let us call one of the thread of your multi
threaded program as parent thread.
Right.
Now this parent thread decides to create a new child thread at the fork point F, right.
Now this time this child thread is created in the detached mode right after the creation of this new
child thread.
The parent thread resumes its execution along its execution flow.
Right.
And child thread also does the same.
It begins its execution along its own execution flow.
Right?
Now, when the child thread has done its job and when it terminates, then immediately all the resources
of the thread are released by the Kernel's process manager immediately.
Right.
There is absolutely no need for the detached thread to come and join the parent thread at the join point
When the parent thread creates a child thread in the detached mode, there is no need for the parent
thread to invoke p thread join API.
Right.
That is, there is no need for the parent thread to block at the join point.
When the data is thread dominates, they do not join any parent thread.
As simple as that.
So it simply means that resources of the data as thread are released as soon as the thread terminates.
Whereas in case of Joinable thread, the resources of the child thread do not release until the child
Joinable thread joins the parent thread.
A detached thread can be converted into joinable while it is running or vice versa and detached thread
do not return any result to joining thread.
Right.
How can they return the result to the joining thread when they do not join the parent thread?
Right?
So it simply means that data is threads work, They do their job and silently die without telling anybody.
Right.
Whereas Joinable thread notifies the parent thread about its death.
Right.
Now let us create a demo program and see how joinable and detached thread can be created.
And what else can we do?