Thread
Thread
#include <icy/thread.h>class ThreadDefined 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
| Name | Kind | Owner |
|---|---|---|
Thread | function | Declared here |
Thread | function | Declared here |
~Thread | function | Declared here |
start | function | Declared here |
start | function | Declared here |
join | function | Declared here |
id | function | Declared here |
mainID | variable | Declared here |
currentID | function | Declared here |
_thread | variable | Declared here |
Thread | function | Declared here |
operator= | function | Declared here |
Thread | function | Declared here |
operator= | function | Declared here |
async | function | Declared here |
Ptr | typedef | Declared here |
Runner | function | Inherited from Runner |
~Runner | function | Inherited from Runner |
start | function | Inherited from Runner |
running | function | Inherited from Runner |
cancel | function | Inherited from Runner |
cancelled | function | Inherited from Runner |
repeating | function | Inherited from Runner |
setRepeating | function | Inherited from Runner |
async | function | Inherited from Runner |
tid | function | Inherited from Runner |
waitForExit | function | Inherited from Runner |
_context | variable | Inherited from Runner |
Runner | function | Inherited from Runner |
operator= | function | Inherited from Runner |
Runner | function | Inherited from Runner |
operator= | function | Inherited from Runner |
Inherited from Runner
| Kind | Name | Description |
|---|---|---|
function | Runner | |
function | ~Runner virtual | |
function | start virtual | Starts the asynchronous context with the given callback. The callback must remain valid for the lifetime of the [Runner](icy-Runner.html#runner). |
function | running const | Returns true if the async context is currently running. |
function | cancel | Signals the async context to stop at the earliest opportunity. |
function | cancelled const | Returns true if the context has been cancelled. The implementation is responsible for exiting as soon as possible after cancellation. |
function | repeating const | Returns true if the runner is in repeating mode. |
function | setRepeating | Enables 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). |
function | async virtual const | Returns true if the implementation is thread-based. |
function | tid const | Returns the native thread ID of the thread running the async context. |
function | waitForExit | Blocks 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 | _context | Shared pointer to the internal Context. |
function | Runner | NonCopyable and NonMovable. |
function | operator= | Deleted assignment operator. |
function | Runner | Deleted constructor. |
function | operator= | Deleted assignment operator. |
Public Methods
| Return | Name | Description |
|---|---|---|
Thread | Default constructor. | |
Thread inline explicit | Constructs a [Thread](#thread-1) and immediately starts it with the given function and arguments. | |
~Thread virtual | Destructor. | |
void | start inline | Starts the thread with a variadic function and arguments. The thread is started immediately; the previous thread must have exited before calling again. |
void | start virtual override | Starts the thread with a std::function callback. Overrides [Runner::start](icy-Runner.html#start-3); delegates to the variadic start template. |
void | join | Wait until the thread exits. |
std::thread::id | id const | Return 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
FunctionCallable type.ArgsArgument types forwarded to the function.
Parameters
funcCallable to execute on the new thread.argsArguments forwarded tofunc.
~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
FunctionCallable type.ArgsArgument types forwarded to the function.
Parameters
funcCallable to execute on the new thread.argsArguments forwarded tofunc.
start
virtual override
virtual void start(std::function< void()> func) overrideDefined 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
funcCallable 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() constDefined in src/base/include/icy/thread.h:79
Return the native thread handle.
Public Static Attributes
| Return | Name | Description |
|---|---|---|
const std::thread::id | mainID static | Accessor for the main thread ID. |
mainID
static
const std::thread::id mainIDDefined in src/base/include/icy/thread.h:85
Accessor for the main thread ID.
Public Static Methods
| Return | Name | Description |
|---|---|---|
std::thread::id | currentID static | Return 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
| Return | Name | Description |
|---|---|---|
std::thread | _thread |
_thread
std::thread _threadDefined in src/base/include/icy/thread.h:96
Protected Methods
| Return | Name | Description |
|---|---|---|
Thread | NonCopyable and NonMovable. | |
Thread | Deleted constructor. | |
bool | async virtual const override | Returns true if the implementation is thread-based. |
Thread
Thread(const Thread &) = deleteDefined in src/base/include/icy/thread.h:89
NonCopyable and NonMovable.
Thread
Thread(Thread &&) = deleteDefined in src/base/include/icy/thread.h:91
Deleted constructor.
async
virtual const override
virtual bool async() const overrideDefined 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
| Name | Description |
|---|---|
Ptr |
Ptr
using Ptr = std::shared_ptr< Thread >