Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > P

pthread_create(3T)

Pthread Library
HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

pthread_create() — create a new thread of execution.

SYNOPSIS

#include <pthread.h>

int pthread_create( pthread_t *__restrict thread, const pthread_attr_t *__restrict attr, void *(*start_routine)(void *), void *__restrict arg );

PARAMETERS

thread

Pointer to the location where the created thread's ID is to be returned.

attr

Pointer to the thread attributes object describing the characteristics of the created thread. If the value is NULL, default attributes will be used.

start_routine

Function to be executed by the newly created thread.

arg

Parameter to be passed to the created thread's start_routine.

DESCRIPTION

The pthread_create() function is used to create a new independent thread within the calling process. The thread will be created according to the attributes specified by attr. If attr is NULL, the default attributes will be used. The values of the attributes in attr describe the characteristics of the to-be-created thread in detail. Refer to the function pthread_attr_init() for a list of the default attribute values. A single attributes object can be used in multiple calls to the function pthread_create().

When a thread is created with an attributes object, the attributes are, in effect, copied into the created thread. Consequently, any change to the attributes object will not affect any previously created threads. Once all threads needing a specific attributes object have been created, the attributes object is no longer needed and may be destroyed.

When the new thread is created, it will execute start_routine(), which has only one parameter, arg. If start_routine() returns, an implicit call to pthread_exit() is made. The return value of start_routine() is used as the thread's exit status.

The created thread's scheduling policy and priority, contention scope, detach state, stack size, and stack address are initialized according to their respective attributes in attr. The thread's signal mask is inherited from the creating thread. The thread's set of pending signals is cleared.

Refer to pthread_exit(3T), pthread_detach(3T), and pthread_join(3T) for more information on thread termination and synchronizing with terminated threads.

On success, the ID of the created thread is returned in thread. If pthread_create() fails, a thread is not created and the contents of thread are undefined.

Thread IDs are guaranteed to be unique only within a process.

NOTE: If the main thread returns from main(), an implicit call to exit() is made. The return value of main() is used as the process' exit status. The main thread can terminate without causing the process to terminate by calling pthread_exit().

Notes

It is unspecified whether joinable threads that have exited but haven't been joined count against the PTHREAD_THREADS_MAX limit.

RETURN VALUE

Upon successful completion, pthread_create() returns zero. Otherwise, an error number is returned to indicate the error (the errno variable is not set).

ERRORS

If any of the following occur, the pthread_create() function returns the corresponding error number:

EINVAL

attr in an invalid thread attributes object.

EINVAL

The value specified by thread is invalid.

EAGAIN

The necessary resources to create another thread are not available, or the number of threads in the calling process already equals PTHREAD_THREADS_MAX.

EINVAL

The scheduling policy or scheduling attributes specified in attr are invalid.

EPERM

The caller does not have the appropriate privileges to create a thread with the scheduling policy and parameters specified in attr.

AUTHOR

pthread_create() was derived from the IEEE POSIX P1003.1c standard.

STANDARDS CONFORMANCE

pthread_create(): POSIX 1003.1c.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.