Creates a thread.
pthread_create( thread, attr, start_routine, arg );
Argument Data Type Accessthread opaque pthread_t write attr opaque pthread_attr_t read start_routine procedure read arg user_arg read
#includeint pthread_create ( pthread_t *thread, const pthread_attr_t *attr, void * (*start_routine) (void *), void *arg);
Successful execution of this routine includes the following actions:
A thread is created in the ready state to begin executing the function specified by the start_routine argument. The new thread may execute immediately. The newly created thread may preempt its creator, depending on scheduling policy and priority. The thread identifier (pthread_t) specified in pthread_create will be written before the new thread executes.
The new thread's scheduling policy and priority are, by default, inherited from the creating thread-the scheduling policy and priority set in the attributes object are ignored. To create a thread using the scheduling policy and priority set in the attributes object, you must first disable the inherit scheduling attribute by calling pthread_attr_setinheritsched before calling pthread_create.
The thread exists until it is both terminated and detached. A thread is detached when created if the detach state attribute of its thread object is set to PTHREAD_CREATE_DETACHED. It is also detached after any thread returns successfully from calling pthread_detach or pthread_join for the thread. Termination is explained in the next section (see Thread Termination).
The caller of pthread_create can synchronize with the newly created thread through the use of the pthread_join routine, or any other mutexes or condition variables they agree to use.
On Digital UNIX, the signal state of the new thread is initialized as follows:
If pthread_create fails, no new thread is created, and the contents of the location referenced by thread are undefined.
A thread terminates when one of the following events occurs:
The following actions are performed when a thread terminates:
If the start routine returns normally and the start routine is a procedure that does not return a value, then the result obtained by pthread_join is unpredictable.
Return Description0 Successful completion. [EAGAIN] The system lacks the necessary resources to create another thread, or the system-imposed limit on the total number of threads under execution by a single user is exceeded. [EINVAL] The value specified by attr is invalid. [ENOMEM] Insufficient enough memory exists to create a thread. [EPERM] The caller does not have the appropriate permission to create a thread with the specified attributes.
pthread_atfork pthread_attr_destroy pthread_attr_init pthread_attr_setdetachstate pthread_attr_setinheritsched pthread_attr_setschedparam pthread_attr_setschedpolicy pthread_attr_setstacksize pthread_cancel pthread_detach pthread_exit pthread_join