pthread_key_create.txt

来自「Pthread lib库完整说明文档」· 文本 代码 · 共 96 行

TXT
96
字号
           --------------------------------------------------------------------------------AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume                                       1--------------------------------------------------------------------------------pthread_key_create SubroutinePurposeCreates a thread-specific data key.LibraryThreads Library (libpthreads.a)Syntax#include <pthread.h>int pthread_key_create ( key, destructor )pthread_key_t * key;void (*destructor) (void *);DescriptionThe pthread_key_create subroutine creates a thread-specific data key. The key isshared among all threads within the process, but each thread has specific dataassociated with the key. The thread-specific data is a void pointer, initiallyset to NULL.The application is responsible for ensuring that this subroutine is called onlyonce for each requested key. This can be done, for example, by calling thesubroutine before creating other threads, or by using the one-time initializationfacility.Typically, thread-specific data are pointers to dynamically allocated storage.When freeing the storage, the value should be set to NULL. It is not recommendedto cast this pointer into scalar data type (int for example), because the castsmay not be portable, and because the value of NULL is implementation dependent.An optional destructor routine can be specified. It will be called for eachthread when it is terminated and detached, after the call to the cleanuproutines, if the specific value is not NULL. Typically, the destructor routinewill release the storage thread-specific data. It will receive thethread-specific data as a parameter.    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.Parameterskey Points to where the key will be stored.destructor Points to an optional destructor routine, used to cleanup data onthread termination. If no cleanup is desired, this pointer should be NULL.Return ValuesIf successful, the pthread_key_create function stores the newly created key valueat *key and returns zero. Otherwise, an error number is returned to indicate theerror.Error CodesThe pthread_key_create function will fail if:EAGAIN The system lacked the necessary resources to create anotherthread-specific data key, or the system-imposed limit on the total number of keysper process PTHREAD_KEYS_MAX has been exceeded.ENOMEM Insufficient memory exists to create the key.The pthread_key_create function will not return an error code of EINTR.Implementation SpecificsThis subroutine is part of the Base Operating System (BOS) Runtime.Related InformationThe pthread_exit subroutine, pthread_key_delete subroutine, pthread_getspecificsubroutne, pthread_once subroutine, pthread.h file.Thread-Specific Data in AIX Version 4.3 General Programming Concepts: Writing andDebugging Programs.Threads Library Quick Reference in AIX Version 4.3 General Programming Concepts:Writing and Debugging Programs.--------------------------------------------------------------------------------           

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?