Linux and UNIX Man Pages

Test Your Knowledge in Computers #582
Difficulty: Medium
A buffered input or output stream is one in which data that is read or written is actually stored in memory in a buffer until such a time as the buffer is flushed and the accumulated data is passed to or from the actual file.
True or False?
Linux & Unix Commands - Search Man Pages

pthread_join(3) [redhat man page]

PTHREAD_JOIN(3) 					     Library Functions Manual						   PTHREAD_JOIN(3)

pthread_join - wait for termination of another thread SYNOPSIS
#include <pthread.h> int pthread_join(pthread_t th, void **thread_return); DESCRIPTION
pthread_join suspends the execution of the calling thread until the thread identified by th terminates, either by calling pthread_exit(3) or by being cancelled. If thread_return is not NULL, the return value of th is stored in the location pointed to by thread_return. The return value of th is either the argument it gave to pthread_exit(3), or PTHREAD_CANCELED if th was cancelled. The joined thread th must be in the joinable state: it must not have been detached using pthread_detach(3) or the PTHREAD_CREATE_DETACHED attribute to pthread_create(3). When a joinable thread terminates, its memory resources (thread descriptor and stack) are not deallocated until another thread performs pthread_join on it. Therefore, pthread_join must be called once for each joinable thread created to avoid memory leaks. At most one thread can wait for the termination of a given thread. Calling pthread_join on a thread th on which another thread is already waiting for termination returns an error. CANCELLATION
pthread_join is a cancellation point. If a thread is canceled while suspended in pthread_join, the thread execution resumes immediately and the cancellation is executed without waiting for the th thread to terminate. If cancellation occurs during pthread_join, the th thread remains not joined. RETURN VALUE
On success, the return value of th is stored in the location pointed to by thread_return, and 0 is returned. On error, a non-zero error code is returned. ERRORS
ESRCH No thread could be found corresponding to that specified by th. EINVAL The th thread has been detached. EINVAL Another thread is already waiting on termination of th. EDEADLK The th argument refers to the calling thread. AUTHOR
Xavier Leroy <> SEE ALSO
pthread_exit(3), pthread_detach(3), pthread_create(3), pthread_attr_setdetachstate(3), pthread_cleanup_push(3), pthread_key_create(3). LinuxThreads PTHREAD_JOIN(3)

Check Out this Related Man Page

PTHREAD_JOIN(3) 					     Linux Programmer's Manual						   PTHREAD_JOIN(3)

pthread_join - join with a terminated thread SYNOPSIS
#include <pthread.h> int pthread_join(pthread_t thread, void **retval); Compile and link with -pthread. DESCRIPTION
The pthread_join() function waits for the thread specified by thread to terminate. If that thread has already terminated, then pthread_join() returns immediately. The thread specified by thread must be joinable. If retval is not NULL, then pthread_join() copies the exit status of the target thread (i.e., the value that the target thread supplied to pthread_exit(3)) into the location pointed to by *retval. If the target thread was canceled, then PTHREAD_CANCELED is placed in *retval. If multiple threads simultaneously try to join with the same thread, the results are undefined. If the thread calling pthread_join() is canceled, then the target thread will remain joinable (i.e., it will not be detached). RETURN VALUE
On success, pthread_join() returns 0; on error, it returns an error number. ERRORS
EDEADLK A deadlock was detected (e.g., two threads tried to join with each other); or thread specifies the calling thread. EINVAL thread is not a joinable thread. EINVAL Another thread is already waiting to join with this thread. ESRCH No thread with the ID thread could be found. CONFORMING TO
After a successful call to pthread_join(), the caller is guaranteed that the target thread has terminated. Joining with a thread that has previously been joined results in undefined behavior. Failure to join with a thread that is joinable (i.e., one that is not detached), produces a "zombie thread". Avoid doing this, since each zombie thread consumes some system resources, and when enough zombie threads have accumulated, it will no longer be possible to create new threads (or processes). There is no pthreads analog of waitpid(-1, &status, 0), that is, "join with any terminated thread". If you believe you need this function- ality, you probably need to rethink your application design. All of the threads in a process are peers: any thread can join with any other thread in the process. EXAMPLE
See pthread_create(3). SEE ALSO
pthread_cancel(3), pthread_create(3), pthread_detach(3), pthread_exit(3), pthread_tryjoin_np(3), pthreads(7) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at Linux 2008-11-27 PTHREAD_JOIN(3)