When the function (declared as a thread) reaches its end, it is removed from the scheduling queue and from the parent thread list of children. If that thread has no children it wishes to wait for, its descriptor is stack space will be reclaimed and the thread will be physically destroyed. Otherwise, the destruction stage will be postponed until all its children die. There are the following important aspects of this scheme of thread destruction:
-
clean semantics -- related threads form a tree which represents relations
-
threads' parameters which were declared as automatic variables in a parent thread will still be valid, even when the parent thread finished its execution
|