DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

pthread_create(PTHREAD)


pthread_create -- thread creation

Synopsis

cc [options] -Kthread file

#include <pthread.h>

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

Description

pthread_create is used to create a new thread, with attributes specified by attr, within a process. If attr is NULL, the default attributes (described on pthread_attr_init(PTHREAD)) are used. If the attributes specified by attr are modified later, the thread's attributes are not affected. Upon successful completion, pthread_create stores the ID of the created thread in the location referenced by thread.

For PTHREAD_SCOPE_PROCESS threads, only the SCHED_OTHER scheduling class can be specified.

The thread is created executing start_routine with arg as its sole argument. If the start_routine returns, the effect is as if there was an implicit call to pthread_exit(PTHREAD) using the return value of start_routine as the exit status. Note that the thread in which main was originally invoked differs from this. When it returns from main, the effect is as if there was an implicit call to exit using the return value of main as the exit status.

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.

Return Values

If successful, pthread_create returns zero. Otherwise, an error number is returned to indicate the error.

Diagnostics

If any of the following conditions is detected, pthread_create will return the corresponding value:

EAGAIN
the system lacked the necessary resources to create another thread

EINVAL
attr is invalid.

EINVAL
a scheduling class other than SCHED_OTHER was specified for a PTHREAD_SCOPE_PROCESS thread

EPERM
the caller does not have appropriate permission to set the required scheduling parameters or scheduling policy

Warnings

SCHED_OTHER is the only scheduling class currently supported for PTHREAD_SCOPE_PROCESS threads.

References

pthread_attr_init(PTHREAD), pthread_exit(PTHREAD), pthread_join(PTHREAD), fork(S), pthread(F)

Standards compliance

The Single UNIX Specification, Version 2; The Open Group.
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005