A thread's thread state is either joinable or unjoinable.
#include <prthread.h> typedef enum PRThreadState { PR_JOINABLE_THREAD, PR_UNJOINABLE_THREAD } PRThreadState;
PR_UNJOINABLE_THREAD
PR_UNJOINABLE_THREAD
state cannot be used as arguments to PR_JoinThread
.PR_JOINABLE_THREAD
PR_JoinThread
is called. This approach facilitates management of the process' critical resources.A thread is a critical resource and must be managed.
The lifetime of a thread extends from the time it is created to the time it returns from its root function. What happens when it returns from its root function depends on the thread state passed to PR_CreateThread
when the thread was created.
If a thread is created as a joinable thread, it continues to exist after returning from its root function until another thread joins it. The join process permits strict synchronization of thread termination and therefore promotes effective resource management.
If a thread is created as an unjoinable (also called detached) thread, it terminates and cleans up after itself after returning from its root function. This results in some ambiguity after the thread's root function has returned and before the thread has finished terminating itself.