Whether the stack returns as soon as the thread exits depends on the OS.
The following stream is well read: link .
I find the following post by Roger Faulkner quite interesting:
At least in Solaris 9 and 10, the thread threads that the library allocated (using mmap ()) are freed up for reuse immediately after the thread termination. A thread structure containing the thread ID and return value is not freed until pthread_join () (or pthread_detach ()).
For quick reuse for a new cache, a cache of up to 10 threads is stored. Old stacks outside the cache - munmap () d.
On my Ubuntu system, the stack is not restored until pthread_join() is called. I suspect this is just an implementation artifact, not a conscious design decision.
source share