Lumiera  0.pre.03
»edit your freedom«
ThreadWrapper Struct Reference

#include "lib/thread.hpp"

Description

wraps the C++ thread handle and provides some implementation details, which are then combined by the policy template

Definition at line 173 of file thread.hpp.

Public Member Functions

 ThreadWrapper ()
 
 ThreadWrapper (string const &threadID)
 
void detach_thread_from_wrapper ()
 allow to detach explicitly — independent from thread-function's state. More...
 
void handle_after_thread ()
 called immediately before end of thread
 
void handle_begin_thread ()
 called immediately at start of thread
 
void handle_loose_thread ()
 called when destroying wrapper on still running thread
 
bool invokedWithinThread () const
 detect if the currently executing code runs within this thread More...
 
bool isLive () const
 
template<class... INVO>
void launchThread (tuple< INVO... > &&invocation)
 
void markThreadEnd ()
 
void markThreadStart ()
 
void setThreadName ()
 
void waitGracePeriod () noexcept
 

Static Public Member Functions

static string decorate_with_global_count (string const &)
 Helper to create a suffix to the thread-ID with running count.
 

Public Attributes

const string threadID_
 
std::thread threadImpl_
 

Additional Inherited Members

- Protected Member Functions inherited from MoveOnly
 MoveOnly (MoveOnly &&)=default
 
 MoveOnly (MoveOnly const &)=delete
 
MoveOnlyoperator= (MoveOnly &&)=delete
 
MoveOnlyoperator= (MoveOnly const &)=delete
 

Constructor & Destructor Documentation

◆ ThreadWrapper()

ThreadWrapper ( )
inline

derived classes may create an inactive thread

Definition at line 183 of file thread.hpp.

Member Function Documentation

◆ launchThread()

void launchThread ( tuple< INVO... > &&  invocation)
inline

actually launch the new thread. Deliberately the #threadImpl_ is created empty, to allow for complete initialisation of all the combined policy classes stacked on top

Warning
Start of the new thread syncs-with the return from std::thread ctor. Thus – in theory – initialising members of derived classes after constructing a non-empty std::thread object would be undefined behaviour. In practice however, this is more of a „theoretical“ problem, since the OS scheduler has a considerable latency, so that the code within the new thread typically starts executing with an delay of at least 100µs
Remarks
non the less, the thread-wrapper framework circumvents this possible undefined behaviour, by first creating the threadImpl_ empty, and only later move-assigning the std::thread.
Parameters
invocationa tuple holding some invokable and possible arguments, together forming the threadFunction to be executed in the new thread.

Definition at line 209 of file thread.hpp.

◆ invokedWithinThread()

bool invokedWithinThread ( ) const

detect if the currently executing code runs within this thread

Note
implies get_id() != std::thread::id{} ==> it is running

Definition at line 74 of file thread.cpp.

References ERROR_LOG_AND_IGNORE.

Referenced by DispatcherLoop::runSessionThread().

+ Here is the caller graph for this function:

◆ detach_thread_from_wrapper()

void detach_thread_from_wrapper ( )
inline

allow to detach explicitly — independent from thread-function's state.

Warning
this function is borderline dangerous; it might be acceptable in a situation where the thread totally manages itself and the thread object is maintained in a unique_ptr. You must ensure that the thread function does not touch anything in the wrapper object after that point and only uses storage within its own scope.

Definition at line 239 of file thread.hpp.

Referenced by SchedulerCommutator_test::blockGroomingToken(), and DispatcherLoop::DispatcherLoop().

+ Here is the caller graph for this function:
+ Inheritance diagram for ThreadWrapper:
+ Collaboration diagram for ThreadWrapper:

The documentation for this struct was generated from the following files: