next up previous contents index
Next: 18.3.26 pthread_detach: Detach a Up: 18.3 POSIX Threads Reference Previous: 18.3.24 pthread_cond_timedwait: Wait on

18.3.25 pthread_create: Create a new thread and start it running

 

SYNOPSIS

#include <oskit/threads/pthread.h>

int pthread_create(pthread_t *tid, const pthread_attr_t *attr, void (*function)(void *), void *arg);

DESCRIPTION

Create a new thread and schedule it to run. The thread is created using the attributes object attr, which specifies the initial priority, stack size, and detach state. If a NULL attributes object is provided, a system default attributes object is used instead, specifying that the thread is detachable, has priority PRIORITY_NORMAL, and with a reasonable stack size.

This call returns immediately, with the thread id stored in the location given by tid. This thread id should be saved if the application wishes to manipulate the thread's state at some future time.

The new thread is scheduled to run. When the thread starts up, it will call void (*function)(void *arg).

PARAMETERS

tid
A pointer to the location where the thread id should be stored.
attr
A pointer to the thread creation attributes object.
function
The initial function to call when the thread first starts.
arg
The argument to the initial function.

RETURNS

Returns zero on success, storing the tid of the new thread into *tid.

RELATED INFORMATION

pthread_join, pthread_detach, pthread_exit



University of Utah Flux Research Group