This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ike the Unix wait function, the pthread join function can only wait for a speciﬁc thread to terminate. There is no way to instruct pthread wait to wait for an arbitrary thread to terminate. This can complicate our code by forcing us to use other less intuitive mechanisms to detect process termination. Indeed some have argued convincingly that this represents a bug in the speciﬁcation . 11.2.4 Detaching Threads
At any point in time, a thread is joinable or detached. A joinable thread can be reaped and killed by other threads. Its memory resources (such as the stack) are not freed until it is reaped by another thread. In contrast, a detached thread cannot be reaped or killed by other threads. Its memory resources are freed automatically by the system when it terminates. By default, threads are created joinable. In order to avoid memory leaks, each joinable thread should either be explicitly reaped by another thread, or detached by a call to the pthread detach function. 11.2. THREAD CONTROL
#include <pthread.h> int pthread detach(pthread t tid); 569 ret...
View Full Document
- Spring '10
- The American