Loading...
Searching...
No Matches
pthread_threading.h File Reference

Thread creation features. More...

Detailed Description

Thread creation features.

Note
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.
 
int pthread_create (pthread_t *newthread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
 Spawn a new POSIX thread.
 
void pthread_exit (void *retval) NORETURN
 Exit calling pthread.
 
int pthread_join (pthread_t th, void **thread_return)
 Join a pthread.
 
int pthread_detach (pthread_t th)
 Make a pthread unjoinable.
 
pthread_t pthread_self (void)
 Returns the pthread id of the calling/current thread.
 
static int pthread_equal (pthread_t thread1, pthread_t thread2)
 Compared two pthread identifiers.
 

Typedef Documentation

◆ pthread_t

typedef unsigned pthread_t

Datatype to identify a POSIX thread.

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

Note
Cancellation is currently not implemented.
In an embedded system you probably want to supply a statically allocated stack in attr.
Parameters
[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.
Returns
== 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.

Parameters
[in]thpthread to detach.
Returns
== 0 on success. != 0 on error.

◆ pthread_equal()

static int pthread_equal ( pthread_t  thread1,
pthread_t  thread2 
)
inlinestatic

Compared two pthread identifiers.

Returns
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.

Note
Only pthreads must call this function. Native threads must call sched_thread_exit(). A pthread must not call sched_thread_exit().
Parameters
[out]retvalReturn value, supplied to a joining thread.
Returns
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.

Parameters
[in]thpthread to join, the id was supplied by pthread_create()
[out]thread_returnExit code of th.
Returns
== 0 on success. != 0 on error.

◆ pthread_self()

pthread_t pthread_self ( void  )

Returns the pthread id of the calling/current thread.

Note
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.
Returns
> 0 identifies the calling pthread. == 0 if the calling thread is not a pthread.