pthread_threading.h File Reference

Thread creation features. More...

Detailed Description

Thread creation features.

Do not include this header file directly, but pthread.h.

Definition in file pthread_threading.h.

#include "kernel_defines.h"
+ Include dependency graph for pthread_threading.h:
+ This graph shows which files directly or indirectly include this file:

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 Documentation

◆ pthread_t

typedef unsigned pthread_t

Datatype to identify a POSIX thread.

The pthread ids are one off to the index in the internal array.

Definition at line 30 of file pthread_threading.h.

Function Documentation

◆ pthread_create()

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().

Cancellation is currently not implemented.
In an embedded system you probably want to supply a statically allocated stack in attr.
[out]newthreadThe identifier of the new thread.
[in]attrAn attribute set that describes how the new thread should be started.
[in]start_routineThe entry point of the new thread.
[in]argArgument supplied to start_routine.
== 0 on success. != 0 on error.

◆ pthread_detach()

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]thpthread to detach.
== 0 on success. != 0 on error.

◆ pthread_equal()

static int pthread_equal ( pthread_t  thread1,
pthread_t  thread2 

Compared two pthread identifiers.

0 if the ids identify two different threads.

Definition at line 101 of file pthread_threading.h.

◆ pthread_exit()

void pthread_exit ( void *  retval)

Exit calling pthread.

Only pthreads must call this function. Native threads must call sched_thread_exit(). A pthread must not call sched_thread_exit().
[out]retvalReturn value, supplied to a joining thread.
This function does not return.

◆ pthread_join()

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]thpthread to join, the id was supplied by pthread_create()
[out]thread_returnExit code of th.
== 0 on success. != 0 on error.

◆ pthread_self()

pthread_t pthread_self ( void  )

Returns the pthread id of the calling/current thread.

This function should not be used to determine if the calling thread is a pthread. If your logic is sane then there should be no need to do that.
> 0 identifies the calling pthread. == 0 if the calling thread is not a pthread.