FRI-OS
|
Wrapper around a POSIX thread. More...
#include <frios/posix/threads/thread.hpp>
Classes | |
struct | create_error |
Exception class for thread creation errors. More... | |
Public Member Functions | |
thread (void *thread_main(void *), void *thread_data) | |
Starts a new thread with the specified main function and data. More... | |
thread (const thread_attr &attr, void *thread_main(void *), void *thread_data) | |
Starts a new thread with the specified attributes, main function and data. More... | |
thread (thread &&tmp) | |
Threads are movable. | |
~thread (void) | |
Destructor releases any resources associated with the running thread. More... | |
bool | joinable (void) const |
Indicates that the thread is running and it is not detached nor joined. More... | |
bool | detached (void) const |
Indicates that the thread has been detached. More... | |
bool | joined (void) const |
Indicates that the thread has been joined. More... | |
void | detach (void) |
Detaches the thread. More... | |
void * | join (void) |
Joins the thread and retrieves the return value. More... | |
void | wait_for (void) |
Waits for the thread to finish. More... | |
Wrapper around a POSIX thread.
If a thread is successfully constructed it can be in one of the following three states:
thread | ( | void * | thread_mainvoid *, |
void * | thread_data | ||
) |
Starts a new thread with the specified main function and data.
create_error |
thread | ( | const thread_attr & | attr, |
void * | thread_mainvoid *, | ||
void * | thread_data | ||
) |
Starts a new thread with the specified attributes, main function and data.
create_error |
~thread | ( | void | ) |
Destructor releases any resources associated with the running thread.
When the thread is destroyed it must be either joined or detached, otherwise the destruction will fail and the process will be aborted.
References thread::detached(), and thread::joined().
void detach | ( | void | ) |
Detaches the thread.
After detaching the thread is put in the detached state and is running independently. Detached threads cannot be joined.
References thread::detached(), and thread::joined().
bool detached | ( | void | ) | const |
Indicates that the thread has been detached.
Referenced by thread::detach(), thread::join(), thread::joinable(), thread::wait_for(), and thread::~thread().
void* join | ( | void | ) |
Joins the thread and retrieves the return value.
After joining the thread is guaranteed to have finished its execution. Joined threads cannot be detached. This function also returns the result value of the thread.
References thread::detached(), and thread::joined().
Referenced by thread::wait_for().
bool joinable | ( | void | ) | const |
Indicates that the thread is running and it is not detached nor joined.
References thread::detached(), and thread::joined().
bool joined | ( | void | ) | const |
Indicates that the thread has been joined.
Referenced by thread::detach(), thread::join(), thread::joinable(), thread::wait_for(), and thread::~thread().
void wait_for | ( | void | ) |
Waits for the thread to finish.
This function blocks it the thread has not finished its execution yet. The thread must not be detached. If the thread result value is required then join() should be used instead.
References thread::detached(), thread::join(), and thread::joined().