Base module

Thread

Platform-independent wrapper around an operating system thread.

Thread

#include <icy/thread.h>

Inherits: Runner

Platform-independent wrapper around an operating system thread.

This class inherits the [Runner](icy-Runner.html#runner) interface and may be used with any implementation that's powered by an asynchronous [Runner](icy-Runner.html#runner).

Public Methods

ReturnNameDescription
ThreadDefault constructor.
Thread inline explicitConstructs a [Thread](#thread) and immediately starts it with the given function and arguments.
~Thread virtualDestructor.
voidstart inlineStarts the thread with a variadic function and arguments. The thread is started immediately; the previous thread must have exited before calling again.
voidstart virtualStarts the thread with a std::function callback. Overrides [Runner::start](icy-Runner.html#start-3); delegates to the variadic start template.
voidjoinWait until the thread exits.
std::thread::idid constReturn the native thread handle.

Thread

Thread()

Default constructor.


Thread

inline explicit

template<typename Function, typename... Args> inline explicit Thread(Function && func, Args &&... args)

Constructs a [Thread](#thread) and immediately starts it with the given function and arguments.

Parameters

  • Function Callable type.

  • Args Argument types forwarded to the function.

Parameters

  • func Callable to execute on the new thread.

  • args Arguments forwarded to func.


~Thread

virtual

virtual ~Thread()

Destructor.


start

inline

template<typename Function, typename... Args> inline void start(Function && func, Args &&... args)

Starts the thread with a variadic function and arguments. The thread is started immediately; the previous thread must have exited before calling again.

Parameters

  • Function Callable type.

  • Args Argument types forwarded to the function.

Parameters

  • func Callable to execute on the new thread.

  • args Arguments forwarded to func.


start

virtual

virtual void start(std::function< void()> func)

Starts the thread with a std::function callback. Overrides [Runner::start](icy-Runner.html#start-3); delegates to the variadic start template.

Parameters

  • func Callable to execute on the new thread.

join

void join()

Wait until the thread exits.


id

const

std::thread::id id() const

Return the native thread handle.

Public Static Attributes

ReturnNameDescription
const std::thread::idmainID staticAccessor for the main thread ID.

mainID

static

const std::thread::id mainID

Accessor for the main thread ID.

Public Static Methods

ReturnNameDescription
std::thread::idcurrentID staticReturn the native thread ID of the current thread.

currentID

static

static std::thread::id currentID()

Return the native thread ID of the current thread.

Protected Attributes

ReturnNameDescription
std::thread_thread

_thread

std::thread _thread

Protected Methods

ReturnNameDescription
ThreadNonCopyable and NonMovable.
ThreadDeleted constructor.
boolasync virtual constReturns true if the implementation is thread-based.

Thread

Thread(const Thread &) = delete

NonCopyable and NonMovable.


Thread

Thread(Thread &&) = delete

Deleted constructor.


async

virtual const

virtual bool async() const

Returns true if the implementation is thread-based.

Returns

True for thread-backed runners, false for event-loop-driven runners.

Public Types

NameDescription
Ptr

Ptr

std::shared_ptr< Thread > Ptr()