pthread_create.txt
来自「Pthread lib库完整说明文档」· 文本 代码 · 共 132 行
TXT
132 行
--------------------------------------------------------------------------------AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1--------------------------------------------------------------------------------pthread_create SubroutinePurposeCreates a new thread, initializes its attributes, and makes it runnable.LibraryThreads Library (libpthreads.a)Syntax#include <pthread.h>;int pthread_create (pthread_t *thread, const pthread_attr_t *attr, void*(*start_routine) (void *), void *arg) ;DescriptionThe pthread_create subroutine creates a new thread and initializes its attributesusing the thread attributes object specified by the attr parameter. The newthread inherits its creating thread's signal mask; but any pending signal of thecreating thread will be cleared for the new thread.The new thread is made runnable, and will start executing the start_routineroutine, with the parameter specified by the arg parameter. The arg parameter isa void pointer; it can reference any kind of data. It is not recommended to castthis pointer into a scalar data type (int for example), because the casts may notbe portable.After thread creation, the thread attributes object can be reused to createanother thread, or deleted.The thread terminates in the following cases: o The thread returned from its starting routine (the main routine for the initial thread) o The thread called the pthread_exit subroutine o The thread was canceled o The thread received a signal that terminated it o The entire process is terminated due to a call to either the exec or exit subroutines. 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.When multiple threads are created in a process, the FULL_CORE flag is set for allsignals. This means that if a core file is produced, it will be much bigger thana single_threaded application. This is necessary to debug multiple-threadedprocesses.Parametersthread Points to where the thread ID will be stored.attr Specifies the thread attributes object to use in creating the thread. If thevalue is NULL, the default attributes values will be used.start_routine Points to the routine to be executed by the thread.arg Points to the single argument to be passed to the start_routine routine.Return ValuesIf successful, the pthread_create function returns zero. Otherwise, an errornumber is returned to indicate the error.Error CodesThe pthread_create function will fail if:EAGAIN The system lacked the necessary resources to create another thread, or thesystem-imposed limit on the total number of threads in a processPTHREAD_THREADS_MAX would be exceeded.EINVAL The value specified by attr is invalid.EPERM The caller does not have appropriate permission to set the requiredscheduling parameters or scheduling policy.The pthread_create function will not return an error code of EINTR.Implementation SpecificsThis subroutine is part of the Base Operating System (BOS) Runtime.When a process uses the pthread_create function, and thus becomes multi-threaded,the FULL_CORE flag is enabled for all signals. If a signal is received whoseaction is to terminate the process with a core dump, a full dump (usually muchlarger than a regular dump) will be produced. This is necessary so thatmulti-threaded programs can be debugged with the dbx command.The following piece of psuedo-code is an example of how to avoid getting a fullcore. Please note that in this case, debug will not be possible. It may be easierto limit the size of the core with the ulimit command.struct sigaction siga;siga.sa_handler = SIG_DFL;siga.sa_flags = SA_RESTART;SIGINITSET(siga.as_mask);sigaction(<SIGNAL_NUMBER>, &siga, NULL);Related InformationThe core file format.The dbx and ulimit commands.The pthread_attr_init subroutine, pthread_attr_destroy subroutine, pthread_exitsubroutine, pthread_cancel subroutine, pthread_kill subroutine, pthread_selfsubroutine, pthread_once subroutine, pthread_join subroutine, fork subroutine,and the pthread.h file.Creating Threads 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 + -
显示快捷键?