ThreadSchedule 1.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::ThreadWrapper Class Reference

Owning wrapper around std::thread with RAII join-on-destroy semantics. More...

#include <thread_wrapper.hpp>

Inheritance diagram for threadschedule::ThreadWrapper:
[legend]
Collaboration diagram for threadschedule::ThreadWrapper:
[legend]

Public Member Functions

 ThreadWrapper (std::thread &&t) noexcept
template<typename F, typename... Args>
 ThreadWrapper (F &&f, Args &&... args)
 ThreadWrapper (ThreadWrapper const &)=delete
auto operator= (ThreadWrapper const &) -> ThreadWrapper &=delete
 ThreadWrapper (ThreadWrapper &&other) noexcept
auto operator= (ThreadWrapper &&other) noexcept -> ThreadWrapper &
auto release () noexcept -> std::thread
 operator std::thread () &&noexcept
Public Member Functions inherited from threadschedule::BaseThreadWrapper< std::thread, detail::OwningTag >
void join ()
void detach ()
auto joinable () const noexcept -> bool
auto get_id () const noexcept -> id
auto native_handle () noexcept -> native_handle_type
auto set_name (std::string const &name) -> expected< void, std::error_code >
auto get_name () const -> std::optional< std::string >
auto set_priority (ThreadPriority priority) -> expected< void, std::error_code >
auto set_scheduling_policy (SchedulingPolicy policy, ThreadPriority priority) -> expected< void, std::error_code >
auto set_affinity (ThreadAffinity const &affinity) -> expected< void, std::error_code >
auto get_affinity () const -> std::optional< ThreadAffinity >

Static Public Member Functions

template<typename F, typename... Args>
static auto create_with_config (std::string const &name, SchedulingPolicy policy, ThreadPriority priority, F &&f, Args &&... args) -> ThreadWrapper
Static Public Member Functions inherited from threadschedule::BaseThreadWrapper< std::thread, detail::OwningTag >
static auto set_nice_value (int nice_value) -> bool
static auto get_nice_value () -> std::optional< int >

Additional Inherited Members

Public Types inherited from threadschedule::BaseThreadWrapper< std::thread, detail::OwningTag >
using native_handle_type
using id

Detailed Description

Owning wrapper around std::thread with RAII join-on-destroy semantics.

Extends BaseThreadWrapper to provide an owning, movable, non-copyable wrapper over std::thread. Adds automatic lifetime management: the destructor joins the thread if it is still joinable, which means destruction can block until the thread finishes.

Copyability / Movability
  • Not copyable (copy constructor and copy assignment are deleted).
  • Movable. Move construction transfers ownership. Move assignment first joins the currently held thread (blocking!) before taking ownership of the source thread.
Destruction
The destructor calls join() if the thread is joinable. This will block the destroying thread until the managed thread completes. If blocking destruction is undesirable, call detach() or release() before the wrapper goes out of scope.
release()
Transfers ownership of the underlying std::thread out of the wrapper, returning it by value. After release, the wrapper holds a default-constructed (non-joinable) thread and destruction becomes a no-op.
create_with_config()
Factory that creates a thread and attempts to set its name and scheduling policy. Failures from set_name() or set_scheduling_policy() are silently ignored - the thread will still be running but may not have the requested attributes. Check attributes after construction if they are critical.
Thread Safety
Not thread-safe. A single ThreadWrapper must not be mutated concurrently from multiple threads.

Definition at line 551 of file thread_wrapper.hpp.

Constructor & Destructor Documentation

◆ ThreadWrapper() [1/3]

threadschedule::ThreadWrapper::ThreadWrapper ( std::thread && t)
inlinenoexcept

Definition at line 557 of file thread_wrapper.hpp.

◆ ThreadWrapper() [2/3]

template<typename F, typename... Args>
threadschedule::ThreadWrapper::ThreadWrapper ( F && f,
Args &&... args )
inlineexplicit

Definition at line 563 of file thread_wrapper.hpp.

◆ ThreadWrapper() [3/3]

threadschedule::ThreadWrapper::ThreadWrapper ( ThreadWrapper && other)
inlinenoexcept

Definition at line 571 of file thread_wrapper.hpp.

◆ ~ThreadWrapper()

threadschedule::ThreadWrapper::~ThreadWrapper ( )
inlineoverride

Definition at line 589 of file thread_wrapper.hpp.

Member Function Documentation

◆ create_with_config()

template<typename F, typename... Args>
auto threadschedule::ThreadWrapper::create_with_config ( std::string const & name,
SchedulingPolicy policy,
ThreadPriority priority,
F && f,
Args &&... args ) -> ThreadWrapper
inlinestatic

Definition at line 610 of file thread_wrapper.hpp.

◆ operator std::thread()

threadschedule::ThreadWrapper::operator std::thread ( ) &&
inlineexplicitnoexcept

Definition at line 603 of file thread_wrapper.hpp.

◆ operator=()

auto threadschedule::ThreadWrapper::operator= ( ThreadWrapper && other) -> ThreadWrapper&
inlinenoexcept

Definition at line 576 of file thread_wrapper.hpp.

◆ release()

auto threadschedule::ThreadWrapper::release ( ) -> std::thread
inlinenoexcept

Definition at line 598 of file thread_wrapper.hpp.


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