pthread_exit.txt
来自「Pthread lib库完整说明文档」· 文本 代码 · 共 95 行
TXT
95 行
--------------------------------------------------------------------------------AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1--------------------------------------------------------------------------------pthread_exit SubroutinePurposeTerminates the calling thread.LibraryThreads Library (libpthreads.a)Syntax#include <pthread.h>void pthread_exit (void *value_ptr);DescriptionThe pthread_exit subroutine terminates the calling thread safely, and stores atermination status for any thread that may join the calling thread. Thetermination status is always a void pointer; it can reference any kind of data.It is not recommended to cast this pointer into a scalar data type (int forexample), because the casts may not be portable. This subroutine never returns.Unlike the exit subroutine, the pthread_exit subroutine does not close files.Thus any file opened and used only by the calling thread must be closed beforecalling this subroutine. It is also important to note that the pthread_exitsubroutine frees any thread-specific data, including the thread's stack. Any dataallocated on the stack becomes invalid, since the stack is freed and thecorresponding memory may be reused by another thread. Therefore, threadsynchronization objects (mutexes and condition variables) allocated on a thread'sstack must be destroyed before the thread calls the pthread_exit subroutine.Returning from the initial routine of a thread implicitly calls the pthread_exitsubroutine, using the return value as parameter.If the thread is not detached, its resources, including the thread ID, thetermination status, the thread-specific data, and its storage, are all maintaineduntil the thread is detached or the process terminates.If another thread joins the calling thread, that thread wakes up immediately, andthe calling thread is automatically detached.If the thread is detached, the cleanup routines are popped from their stack andexecuted. Then the destructor routines from the thread-specific data areexecuted. Finally, the storage of the thread is reclaimed and its ID is freed forreuse.Terminating the initial thread by calling this subroutine does not terminate theprocess, it just terminates the initial thread. However, if all the threads inthe process are terminated, the process is terminated by implicitly calling theexit subroutine with a return code of 0 if the last thread is detached, or 1otherwise. Note: The pthread.h header file must be the first included file of each source file using the threads library. Otherwise, the -D_THREAD_SAFE compilation flag should be used, or the cc_r compiler used. In this case, the flag is automatically set.Parametersstatus Points to an optional termination status, used by joining threads. If notermination status is desired, its value should be NULL.Return ValuesThe pthread_exit function cannot return to its caller.ErrorsNo errors are defined.The pthread_exit function will not return an error code of EINTR.Implementation SpecificsThis subroutine is part of the Base Operating System (BOS) Runtime.Related InformationThe pthread_cleanup_push subroutine, pthread_cleanup_pop subroutine,pthread_key_create subroutine, pthread_create subroutine, pthread_joinsubroutine, pthread_cancel subroutine, exit subroutine, the pthread.h file.Terminating Threads and Threads Library Quick Reference in AIX Version 4.3General Programming Concepts: Writing and Debugging Programs.--------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?