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

Non-owning control view found by an exact process-thread name. More...

#include <thread_by_name_view.hpp>

Public Member Functions

 thread_by_name_view (std::string_view name)
 Find exactly one process thread with name.
 
auto alive () const noexcept -> bool
 Return whether the original native thread identity is still live.
 
auto native_id () const noexcept -> native_thread_id
 Return the platform-native process thread ID.
 
auto configure (thread_config const &config) -> result< void >
 Apply a portable thread configuration to the target.
 
auto set_priority (priority_level level) -> result< void >
 Set a portable priority preset on the target.
 
auto set_nice (nice_value value) -> result< void >
 Set an explicit nice value on the target.
 
auto get_priority () const -> result< priority_level >
 Query the effective portable priority preset.
 
auto get_nice () const -> result< nice_value >
 Query the effective nice value.
 
auto set_name (std::string const &name) -> result< void >
 Set the OS-visible target name without changing view identity.
 
auto get_name () const -> result< std::string >
 Query the current OS-visible target name.
 
auto set_affinity (thread_affinity const &affinity) -> result< void >
 Set target CPU affinity with exact readback and rollback.
 
auto get_affinity () const -> result< thread_affinity >
 Query target CPU affinity.
 

Static Public Member Functions

static auto create (std::string_view name) -> result< thread_by_name_view >
 Find exactly one named process thread without throwing.
 
static auto find_all (std::string_view name) -> result< std::vector< thread_by_name_view > >
 Return every exact name match ordered by native thread ID.
 

Detailed Description

Non-owning control view found by an exact process-thread name.

Linux lookup scans /proc/self/task and compares the kernel-visible comm name exactly. A view stores both the native thread ID and the thread start time, so an exited thread or a recycled ID is rejected with std::errc::no_such_process.

Lookup is snapshot-based. Renaming the target does not retarget an existing view, and a matching thread created after lookup does not affect it.

Warning
Linux exposes only numeric TIDs to these native control calls. A thread can still exit in the small interval between the identity check and the syscall. Registry-backed control is required when lifecycle coupling must close that race.

Definition at line 39 of file thread_by_name_view.hpp.

Constructor & Destructor Documentation

◆ thread_by_name_view()

threadschedule::advanced::thread_by_name_view::thread_by_name_view ( std::string_view  name)
inlineexplicit

Find exactly one process thread with name.

Exceptions
std::system_errorfor no match, ambiguous matches, invalid input, or an unsupported platform.

Definition at line 47 of file thread_by_name_view.hpp.

Member Function Documentation

◆ alive()

auto threadschedule::advanced::thread_by_name_view::alive ( ) const -> bool
inlinenoexcept

Return whether the original native thread identity is still live.

Definition at line 87 of file thread_by_name_view.hpp.

References threadschedule::detail::native_thread_is_alive().

◆ configure()

auto threadschedule::advanced::thread_by_name_view::configure ( thread_config const &  config) -> result<void>
inline

◆ create()

static auto threadschedule::advanced::thread_by_name_view::create ( std::string_view  name) -> result<thread_by_name_view>
inlinestatic

Find exactly one named process thread without throwing.

Definition at line 51 of file thread_by_name_view.hpp.

References threadschedule::detail::try_result().

◆ find_all()

static auto threadschedule::advanced::thread_by_name_view::find_all ( std::string_view  name) -> result<std::vector<thread_by_name_view>>
inlinestatic

Return every exact name match ordered by native thread ID.

Returns
An empty vector when no process thread has the requested name.

Definition at line 68 of file thread_by_name_view.hpp.

References threadschedule::detail::find_native_threads_by_name(), and threadschedule::detail::try_result().

◆ get_affinity()

auto threadschedule::advanced::thread_by_name_view::get_affinity ( ) const -> result<thread_affinity>
inline

Query target CPU affinity.

Definition at line 194 of file thread_by_name_view.hpp.

◆ get_name()

auto threadschedule::advanced::thread_by_name_view::get_name ( ) const -> result<std::string>
inline

Query the current OS-visible target name.

Definition at line 175 of file thread_by_name_view.hpp.

◆ get_nice()

auto threadschedule::advanced::thread_by_name_view::get_nice ( ) const -> result<nice_value>
inline

Query the effective nice value.

Definition at line 160 of file thread_by_name_view.hpp.

References threadschedule::detail::read_effective_nice().

◆ get_priority()

auto threadschedule::advanced::thread_by_name_view::get_priority ( ) const -> result<priority_level>
inline

Query the effective portable priority preset.

Definition at line 152 of file thread_by_name_view.hpp.

References threadschedule::detail::read_effective_nice().

◆ native_id()

auto threadschedule::advanced::thread_by_name_view::native_id ( ) const -> native_thread_id
inlinenoexcept

Return the platform-native process thread ID.

Definition at line 94 of file thread_by_name_view.hpp.

References threadschedule::detail::native_thread_identity::id.

◆ set_affinity()

auto threadschedule::advanced::thread_by_name_view::set_affinity ( thread_affinity const &  affinity) -> result<void>
inline

Set target CPU affinity with exact readback and rollback.

Definition at line 182 of file thread_by_name_view.hpp.

References threadschedule::detail::apply_affinity_checked(), threadschedule::detail::to_native(), and threadschedule::detail::try_result().

◆ set_name()

auto threadschedule::advanced::thread_by_name_view::set_name ( std::string const &  name) -> result<void>
inline

Set the OS-visible target name without changing view identity.

Definition at line 168 of file thread_by_name_view.hpp.

Referenced by configure().

◆ set_nice()

auto threadschedule::advanced::thread_by_name_view::set_nice ( nice_value  value) -> result<void>
inline

Set an explicit nice value on the target.

Definition at line 143 of file thread_by_name_view.hpp.

References threadschedule::detail::apply_scheduling_config(), and threadschedule::detail::native_schedule::posix_nice().

◆ set_priority()

auto threadschedule::advanced::thread_by_name_view::set_priority ( priority_level  level) -> result<void>
inline

Set a portable priority preset on the target.

Definition at line 131 of file thread_by_name_view.hpp.

References threadschedule::detail::apply_scheduling_config(), and threadschedule::detail::native_schedule::posix_nice().


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