Thread creation features. More...
Thread creation features.
Definition in file pthread_threading.h.
#include "kernel_defines.h"
Go to the source code of this file.
typedef unsigned | pthread_t |
Datatype to identify a POSIX thread. More... | |
int | pthread_create (pthread_t *newthread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) |
Spawn a new POSIX thread. More... | |
void | pthread_exit (void *retval) NORETURN |
Exit calling pthread. More... | |
int | pthread_join (pthread_t th, void **thread_return) |
Join a pthread. More... | |
int | pthread_detach (pthread_t th) |
Make a pthread unjoinable. More... | |
pthread_t | pthread_self (void) |
Returns the pthread id of the calling/current thread. More... | |
static int | pthread_equal (pthread_t thread1, pthread_t thread2) |
Compared two pthread identifiers. More... | |
typedef unsigned pthread_t |
Datatype to identify a POSIX thread.
Definition at line 30 of file pthread_threading.h.
int pthread_create | ( | pthread_t * | newthread, |
const pthread_attr_t * | attr, | ||
void *(*)(void *) | start_routine, | ||
void * | arg | ||
) |
Spawn a new POSIX thread.
This functions starts a new thread. The thread will be joinable (from another pthread), unless attr
tells to create the thread detached. A non-detached thread must be joined will stay a zombie into it is joined. You can call pthread_exit() inside the thread, or return from start_routine()
.
attr
. [out] | newthread | The identifier of the new thread. |
[in] | attr | An attribute set that describes how the new thread should be started. |
[in] | start_routine | The entry point of the new thread. |
[in] | arg | Argument supplied to start_routine . |
== 0
on success. != 0
on error. int pthread_detach | ( | pthread_t | th | ) |
Make a pthread unjoinable.
The resources of a detached thread get released as soon as it exits, without the need to call pthread_join() out of another pthread. In fact you cannot join a detached thread, it will return an error. Detaching a thread while another thread tries to join it causes undefined behavior. A pthread may detach himself. A non-pthread may call this function, too. A pthread cannot be "attached" again.
[in] | th | pthread to detach. |
== 0
on success. != 0
on error. Compared two pthread identifiers.
0
if the ids identify two different threads. Definition at line 101 of file pthread_threading.h.
void pthread_exit | ( | void * | retval | ) |
Exit calling pthread.
[out] | retval | Return value, supplied to a joining thread. |
int pthread_join | ( | pthread_t | th, |
void ** | thread_return | ||
) |
Join a pthread.
The current thread sleeps until th
exits. The exit value of th
gets written into thread_return
. You can only join pthreads, and only pthreads can join. A thread must not join itself.
[in] | th | pthread to join, the id was supplied by pthread_create() |
[out] | thread_return | Exit code of th . |
== 0
on success. != 0
on error. pthread_t pthread_self | ( | void | ) |
Returns the pthread id of the calling/current thread.
> 0
identifies the calling pthread. == 0
if the calling thread is not a pthread.