Skip to content

Engine → Core → dedicated_thread.h

jobs::dedicated_thread

Syntax

class CONJURE_API dedicated_thread

Constructors

AccessSignatureDescription
publicdedicated_thread( std::string name, std::function<void(std::stop_token)> body);Starts the thread immediately. The name is applied to the OS thread (truncated on a code point boundary to 15 bytes on Linux and macOS and 63 UTF-16 units on Windows). An empty body asserts and leaves the object non-joinable. If the operating system refuses to create the thread, the std::system_error that std::jthread throws is not caught (engine code never catches) and ends the process like an allocation failure.
publicdedicated_thread( dedicated_thread &&) noexcept = default;

Important

Additional constructor overloads have been deleted.

Destructors

AccessSignatureDescription
public~dedicated_thread();Requests a stop and joins when the thread is still running.

Variables

AccessNameTypeDefaultDescription
privatemNamestd::string{}
privatemThreadstd::jthread{}

Functions

Public

get_id

[[nodiscard]] std::thread::id get_id() const noexcept;

Identifier of the underlying thread; default-constructed when not joinable.

join

void join();

Waits for the body to return. Does not request a stop; no-op when not joinable.

joinable

[[nodiscard]] bool joinable() const noexcept;

True while the thread has been started and not yet joined.

name

[[nodiscard]] const std::string &name() const noexcept;

The name given at construction.

request_stop

void request_stop() noexcept;

Signals the body's stop token. Does not wait.

stop_requested

[[nodiscard]] bool stop_requested() const noexcept;

True once request_stop() has been called (or the destructor has started).

Operator Overloads

Public

operator=

dedicated_thread &operator=(
    dedicated_thread &&) noexcept = default;