FRI-OS
Classes | Public Member Functions | List of all members
thread Class Reference

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

Detailed Description

Wrapper around a POSIX thread.

If a thread is successfully constructed it can be in one of the following three states:

Examples:
example/posix/threads-bingo_detached.cpp, example/posix/threads-producer_consumer.cpp, and example/posix/threads-simple_usage.cpp.

Constructor & Destructor Documentation

thread ( void *  thread_mainvoid *,
void *  thread_data 
)

Starts a new thread with the specified main function and data.

Exceptions
create_error
Postcondition
joinable()
thread ( const thread_attr attr,
void *  thread_mainvoid *,
void *  thread_data 
)

Starts a new thread with the specified attributes, main function and data.

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

Precondition
joined() OR detached()

References thread::detached(), and thread::joined().

Member Function Documentation

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.

See Also
joinable
joined
detached
join
Precondition
NOT joined() AND NOT detached()
Postcondition
detached()
Examples:
example/posix/threads-bingo_detached.cpp.

References thread::detached(), and thread::joined().

bool detached ( void  ) const

Indicates that the thread has been detached.

See Also
joinable
joined
detach
join

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.

See Also
joinable
joined
detached
detach
Precondition
NOT joined() AND NOT detached()
Postcondition
joined()

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.

See Also
joined
detached
detach
join

References thread::detached(), and thread::joined().

bool joined ( void  ) const

Indicates that the thread has been joined.

See Also
joinable
detached
join
detach

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.

Precondition
NOT detached()
Postcondition
joined()

References thread::detached(), thread::join(), and thread::joined().


The documentation for this class was generated from the following file: