Lumiera  0.pre.03
»edit your freedom«
ThreadLifecycle< POL, RES > Class Template Reference

#include "lib/thread.hpp"

Description

template<template< class, class > class POL, typename RES = void>
class lib::thread::ThreadLifecycle< POL, RES >

Policy-based configuration of thread lifecycle.

Definition at line 385 of file thread.hpp.

Public Member Functions

 ThreadLifecycle (Launch launcher)
 Primary constructor: Launch the new thread with flexible configuration. More...
 
template<class FUN , typename... ARGS>
 ThreadLifecycle (string const &threadID, FUN &&threadFunction, ARGS &&...args)
 Create a new thread to execute the given operation. More...
 
template<class SUB , typename... ARGS>
 ThreadLifecycle (RES(SUB::*memFun)(ARGS...), ARGS ...args)
 Special variant to bind a subclass member function as thread operation. More...
 
 operator bool () const
 Is this thread »active« and thus tied to OS resources? More...
 

Static Public Member Functions

template<class W , class... INVO>
static auto buildInvocation (W &wrapper, tuple< INVO... > &&invocation)
 Build the invocation tuple, using #invokeThreadFunction to delegate to the user-provided functor and arguments.
 
template<class... INVO>
static auto buildLauncher (INVO &&...args)
 Build a λ actually to launch the given thread operation later, after the thread-wrapper-object is fully initialised. More...
 

Classes

struct  Launch
 Configuration builder to define the operation running within the thread, and possibly configure further details, depending on the actual Policy used. More...
 

Protected Member Functions

 ThreadLifecycle ()
 derived classes may create a disabled thread
 

Private Types

using Policy = POL< ThreadWrapper, RES >
 

Private Member Functions

template<typename... ARGS>
void invokeThreadFunction (ARGS &&...args)
 

Constructor & Destructor Documentation

◆ ThreadLifecycle() [1/3]

ThreadLifecycle ( Launch  launcher)
inline

Primary constructor: Launch the new thread with flexible configuration.

Parameters
launchera #Launch builder with a λ-chain to configure and finally trigger start of the thread

Definition at line 583 of file thread.hpp.

◆ ThreadLifecycle() [2/3]

ThreadLifecycle ( string const &  threadID,
FUN &&  threadFunction,
ARGS &&...  args 
)
inline

Create a new thread to execute the given operation.

The new thread starts up synchronously, can't be cancelled and it can't be joined.

Parameters
threadIDhuman readable descriptor to identify the thread for diagnostics
threadFunctiona functor holding the code to execute within the new thread. Any function-like entity or callable is acceptable; arguments can be given.
Warning
The operation functor and all arguments will be copied into the new thread. The return from this constructor syncs-with the launch of the operation.

Definition at line 599 of file thread.hpp.

◆ ThreadLifecycle() [3/3]

ThreadLifecycle ( RES(SUB::*)(ARGS...)  memFun,
ARGS ...  args 
)
inline

Special variant to bind a subclass member function as thread operation.

Warning
potential race between thread function and subclass initialisation

Definition at line 610 of file thread.hpp.

Member Function Documentation

◆ buildLauncher()

static auto buildLauncher ( INVO &&...  args)
inlinestatic

Build a λ actually to launch the given thread operation later, after the thread-wrapper-object is fully initialised.

The member function #invokeThreadFunction will be run as top-level within the new thread, possibly handling errors, but delegating to the user-provided actual thread-operation

Parameters
argsa invokable + further arguments
Note
the invokable and the arguments will be materialised/copied thereby decaying the given type; this is necessary, because these arguments must be copied into the new thread. This will fail to compile, if the given invokable can not be invoked with these copied (and decayed) arguments.

Definition at line 445 of file thread.hpp.

◆ operator bool()

operator bool ( ) const
inlineexplicit

Is this thread »active« and thus tied to OS resources?

Note
this implies some statefulness, which may contradict the RAII pattern.
  • especially note the possibly for derived classes to create an empty Thread.
  • moreover note that ThreadJoinable may have terminated, but still awaits join().

Definition at line 628 of file thread.hpp.

+ Inheritance diagram for ThreadLifecycle< POL, RES >:
+ Collaboration diagram for ThreadLifecycle< POL, RES >:

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