4 #ifndef __FRIOS_POSIX_THREADS_THREAD_HPP__
5 #define __FRIOS_POSIX_THREADS_THREAD_HPP__
34 void* thread_main(
void*),
38 int fail = pthread_create(
67 void* thread_main(
void*),
72 _start(0, thread_main, thread_data);
80 const thread_attr& attr,
81 void* thread_main(
void*),
84 , _detached(attr.get_detach_state() == thread_attr::detach_state::
detached)
86 _start(&attr._attr, thread_main, thread_data);
91 : _thread(std::move(tmp._thread))
92 , _joined(tmp._joined)
93 , _detached(tmp._detached)
159 int fail = pthread_detach(_thread);
160 if(fail)
throw error(fail);
181 int fail = pthread_join(_thread, &result);
182 if(fail)
throw error(fail);
205 #endif // include guard
void * join(void)
Joins the thread and retrieves the return value.
Definition: thread.hpp:177
Wrapper around POSIX thread attributes.
Definition: thread_attr.hpp:22
void wait_for(void)
Waits for the thread to finish.
Definition: thread.hpp:195
bool detached(void) const
Indicates that the thread has been detached.
Definition: thread.hpp:127
Base class for all POSIX exceptions.
Definition: error.hpp:14
bool joinable(void) const
Indicates that the thread is running and it is not detached nor joined.
Definition: thread.hpp:115
thread(void *thread_main(void *), void *thread_data)
Starts a new thread with the specified main function and data.
Definition: thread.hpp:66
Wrapper around POSIX thread attributes.
bool joined(void) const
Indicates that the thread has been joined.
Definition: thread.hpp:139
thread(const thread_attr &attr, void *thread_main(void *), void *thread_data)
Starts a new thread with the specified attributes, main function and data.
Definition: thread.hpp:79
void detach(void)
Detaches the thread.
Definition: thread.hpp:156
thread(thread &&tmp)
Threads are movable.
Definition: thread.hpp:90
Declaration of exception classes for POSIX errors.
error(int error_code)
Construction from POSIX error code.
Definition: error.hpp:26
~thread(void)
Destructor releases any resources associated with the running thread.
Definition: thread.hpp:102
Wrapper around a POSIX thread.
Definition: thread.hpp:25
Exception class for thread creation errors.
Definition: thread.hpp:53