Home
Base module

Thread

Platform-independent wrapper around an operating system thread.

Thread

#include <icy/thread.h>
class Thread

Defined in src/base/include/icy/thread.h:32

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

List of all members

NameKindOwner
ThreadfunctionDeclared here
ThreadfunctionDeclared here
~ThreadfunctionDeclared here
startfunctionDeclared here
startfunctionDeclared here
joinfunctionDeclared here
idfunctionDeclared here
mainIDvariableDeclared here
currentIDfunctionDeclared here
_threadvariableDeclared here
ThreadfunctionDeclared here
operator=functionDeclared here
ThreadfunctionDeclared here
operator=functionDeclared here
asyncfunctionDeclared here
PtrtypedefDeclared here
RunnerfunctionInherited from Runner
~RunnerfunctionInherited from Runner
startfunctionInherited from Runner
runningfunctionInherited from Runner
cancelfunctionInherited from Runner
cancelledfunctionInherited from Runner
repeatingfunctionInherited from Runner
setRepeatingfunctionInherited from Runner
asyncfunctionInherited from Runner
tidfunctionInherited from Runner
waitForExitfunctionInherited from Runner
_contextvariableInherited from Runner
RunnerfunctionInherited from Runner
operator=functionInherited from Runner
RunnerfunctionInherited from Runner
operator=functionInherited from Runner

Inherited from Runner

KindNameDescription
functionRunner
function~Runner virtual
functionstart virtualStarts the asynchronous context with the given callback. The callback must remain valid for the lifetime of the [Runner](icy-Runner.html#runner).
functionrunning constReturns true if the async context is currently running.
functioncancelSignals the async context to stop at the earliest opportunity.
functioncancelled constReturns true if the context has been cancelled. The implementation is responsible for exiting as soon as possible after cancellation.
functionrepeating constReturns true if the runner is in repeating mode.
functionsetRepeatingEnables or disables repeating mode. When repeating, the target function is invoked repeatedly until [cancel()](icy-Runner.html#cancel-2) is called. This normalizes behaviour across thread-based and event-loop-based [Runner](icy-Runner.html#runner) implementations. Must be called before [start()](icy-Runner.html#start-3).
functionasync virtual constReturns true if the implementation is thread-based.
functiontid constReturns the native thread ID of the thread running the async context.
functionwaitForExitBlocks until the async context exits or the timeout elapses. The context should be cancelled before calling this method. Must be called from outside the runner's own thread to avoid deadlock.
variable_contextShared pointer to the internal Context.
functionRunnerNonCopyable and NonMovable.
functionoperator=Deleted assignment operator.
functionRunnerDeleted constructor.
functionoperator=Deleted assignment operator.

Public Methods

ReturnNameDescription
ThreadDefault constructor.
Thread inline explicitConstructs a [Thread](#thread-1) 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 virtual overrideStarts 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()

Defined in src/base/include/icy/thread.h:38

Default constructor.


Thread

inline explicit

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

Defined in src/base/include/icy/thread.h:46

Constructs a [Thread](#thread-1) 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()

Defined in src/base/include/icy/thread.h:54

Destructor.


start

inline

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

Defined in src/base/include/icy/thread.h:63

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 override

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

Defined in src/base/include/icy/thread.h:73

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

join

void join()

Defined in src/base/include/icy/thread.h:76

Wait until the thread exits.


id

const

std::thread::id id() const

Defined in src/base/include/icy/thread.h:79

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

Defined in src/base/include/icy/thread.h:85

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()

Defined in src/base/include/icy/thread.h:82

Return the native thread ID of the current thread.

Protected Attributes

ReturnNameDescription
std::thread_thread

_thread

std::thread _thread

Defined in src/base/include/icy/thread.h:96

Protected Methods

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

Thread

Thread(const Thread &) = delete

Defined in src/base/include/icy/thread.h:89

NonCopyable and NonMovable.


Thread

Thread(Thread &&) = delete

Defined in src/base/include/icy/thread.h:91

Deleted constructor.


async

virtual const override

virtual bool async() const override

Defined in src/base/include/icy/thread.h:94

Returns true if the implementation is thread-based.

Returns

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

Reimplements

Public Types

NameDescription
Ptr

Ptr

using Ptr = std::shared_ptr< Thread >

Defined in src/base/include/icy/thread.h:35