ThreadSchedule 3.0.0
Modern C++ thread management library
Loading...
Searching...
No Matches
threadschedule::detail::thread_backend Class Reference

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

#include <thread_backend.hpp>

Inheritance diagram for threadschedule::detail::thread_backend:
[legend]
Collaboration diagram for threadschedule::detail::thread_backend:
[legend]

Public Member Functions

 thread_backend ()=default
 
auto get () noexcept -> std::thread &
 
auto get () const noexcept -> std::thread const &
 
 thread_backend (std::thread &&t) noexcept
 
 thread_backend (std::thread &&t, native_thread_id tid) noexcept
 
template<typename F , typename... Args>
 thread_backend (F &&f, Args &&... args)
 
 thread_backend (thread_backend const &)=delete
 
auto operator= (thread_backend const &) -> thread_backend &=delete
 
 thread_backend (thread_backend &&other) noexcept
 
auto operator= (thread_backend &&other) noexcept -> thread_backend &
 
 ~thread_backend () override
 
auto release () noexcept -> std::thread
 
 operator std::thread () &&noexcept
 
- Public Member Functions inherited from threadschedule::detail::basic_thread_backend< std::thread, detail::owning_tag >
 basic_thread_backend ()=default
 
 basic_thread_backend (std::thread &t)
 
 basic_thread_backend (std::thread &t, native_thread_id tid)
 
virtual ~basic_thread_backend ()=default
 
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 -> expected< std::string, std::error_code >
 
auto set_priority (native_thread_priority priority) -> expected< void, std::error_code >
 
auto set_scheduling_policy (native_scheduling_policy policy, native_thread_priority priority) -> expected< void, std::error_code >
 
auto configure (native_scheduling_config const &config) -> expected< void, std::error_code >
 
auto configure (native_thread_config const &config) -> expected< void, std::error_code >
 
auto set_nice_value (int nice_value) -> expected< void, std::error_code >
 
auto get_nice_value () const -> expected< int, std::error_code >
 
auto set_affinity (native_thread_affinity const &affinity) -> expected< void, std::error_code >
 
auto get_affinity () const -> expected< native_thread_affinity, std::error_code >
 
auto native_id () const noexcept -> native_thread_id
 

Static Public Member Functions

template<typename F , typename... Args>
static auto create_with_config (std::string const &name, native_scheduling_policy policy, native_thread_priority priority, F &&f, Args &&... args) -> thread_backend
 
template<typename F , typename... Args>
static auto create_with_config (native_thread_config const &config, F &&f, Args &&... args) -> thread_backend
 

Additional Inherited Members

- Public Types inherited from threadschedule::detail::basic_thread_backend< std::thread, detail::owning_tag >
using native_handle_type = typename ThreadType::native_handle_type
 
using id = typename ThreadType::id
 
- Protected Member Functions inherited from threadschedule::detail::basic_thread_backend< std::thread, detail::owning_tag >
void set_native_id (native_thread_id tid) noexcept
 
- Static Protected Member Functions inherited from threadschedule::detail::basic_thread_backend< std::thread, detail::owning_tag >
static auto no_such_thread () -> unexpected< std::error_code >
 
- Protected Attributes inherited from threadschedule::detail::basic_thread_backend< std::thread, detail::owning_tag >
native_thread_id native_id_
 

Detailed Description

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

Extends basic_thread_backend 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 thread_backend must not be mutated concurrently from multiple threads.

Definition at line 460 of file thread_backend.hpp.

Constructor & Destructor Documentation

◆ thread_backend() [1/6]

threadschedule::detail::thread_backend::thread_backend ( )
default

◆ thread_backend() [2/6]

threadschedule::detail::thread_backend::thread_backend ( std::thread &&  t)
inlinenoexcept

Definition at line 478 of file thread_backend.hpp.

◆ thread_backend() [3/6]

threadschedule::detail::thread_backend::thread_backend ( std::thread &&  t,
native_thread_id  tid 
)
inlinenoexcept

◆ thread_backend() [4/6]

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

◆ thread_backend() [5/6]

threadschedule::detail::thread_backend::thread_backend ( thread_backend const &  )
delete

◆ thread_backend() [6/6]

threadschedule::detail::thread_backend::thread_backend ( thread_backend &&  other)
inlinenoexcept

◆ ~thread_backend()

threadschedule::detail::thread_backend::~thread_backend ( )
inlineoverride

Member Function Documentation

◆ create_with_config() [1/2]

template<typename F , typename... Args>
static auto threadschedule::detail::thread_backend::create_with_config ( native_thread_config const &  config,
F &&  f,
Args &&...  args 
) -> thread_backend
inlinestatic

◆ create_with_config() [2/2]

template<typename F , typename... Args>
static auto threadschedule::detail::thread_backend::create_with_config ( std::string const &  name,
native_scheduling_policy  policy,
native_thread_priority  priority,
F &&  f,
Args &&...  args 
) -> thread_backend
inlinestatic

◆ get() [1/2]

auto threadschedule::detail::thread_backend::get ( ) const -> std::thread const&
inlinenoexcept

Definition at line 472 of file thread_backend.hpp.

◆ get() [2/2]

auto threadschedule::detail::thread_backend::get ( ) -> std::thread&
inlinenoexcept

Definition at line 466 of file thread_backend.hpp.

◆ operator std::thread()

threadschedule::detail::thread_backend::operator std::thread ( ) &&
inlineexplicitnoexcept

Definition at line 550 of file thread_backend.hpp.

References release().

◆ operator=() [1/2]

◆ operator=() [2/2]

auto threadschedule::detail::thread_backend::operator= ( thread_backend const &  ) -> thread_backend &=delete
delete

◆ release()

auto threadschedule::detail::thread_backend::release ( ) -> std::thread
inlinenoexcept

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