The friendly Operating System for the Internet of Things
pthread_threading.h File Reference

Thread creation features. More...

Detailed Description

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

typedef unsigned pthread_t
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

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

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.
int pthread_detach ( pthread_t  th)

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.
static int pthread_equal ( pthread_t  thread1,
pthread_t  thread2 
)
inlinestatic
Returns
0 if the ids identify two different threads.

Definition at line 101 of file pthread_threading.h.

void pthread_exit ( void *  retval)
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.
int pthread_join ( pthread_t  th,
void **  thread_return 
)

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_t pthread_self ( void  )
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.