Detaching a Thread
Introduction
當一個 thread 死亡後,他的狀態會變成 joinable(可以想成跟 process 死亡後變成 zombie 一樣),在這個狀態下,thread 所使用的資源還沒有完全被清除,其 TCB (Thread Control Block) 還待其他 thread 去接收
當其他 thread 用 pthread_join 去 wait 死亡的 thread 後,這個死亡的 thread 才會從 joinable 變成 detached
Detachstate Attribute
我們也可以用 detachstate 來指定我們要不要在死亡時變成 joinable,還是要直接變成 detached