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

Looks up an OS thread by its name via /proc and provides scheduling control. More...

#include <thread_wrapper.hpp>

Public Types

using native_handle_type = pid_t

Public Member Functions

 ThreadByNameView (const std::string &name)
auto found () const noexcept -> bool
auto set_name (std::string const &name) const -> expected< void, std::error_code >
auto get_name () const -> std::optional< std::string >
auto native_handle () const noexcept -> native_handle_type
auto set_priority (ThreadPriority priority) const -> expected< void, std::error_code >
auto set_scheduling_policy (SchedulingPolicy policy, ThreadPriority priority) const -> expected< void, std::error_code >
auto set_affinity (ThreadAffinity const &affinity) const -> expected< void, std::error_code >

Detailed Description

Looks up an OS thread by its name via /proc and provides scheduling control.

On construction, scans /proc/self/task/ to find a thread whose comm matches the given name. If found, the Linux TID is cached and subsequent calls operate on that TID via sched_setscheduler / sched_setaffinity (TID-based syscalls, not pthread_setschedparam).

Platform Support
  • Linux only. On Windows every method is a no-op or returns errc::function_not_supported, and found() always returns false.
Snapshot Semantics
The /proc scan happens once at construction time. If the target thread exits or changes its name after construction, this view becomes stale. There is no live tracking.
Thread Name Limit
Linux thread names are limited to 15 characters. Names longer than 15 characters will never match, and set_name() rejects them.
Scheduling
Uses sched_setscheduler(tid, ...) rather than pthread_setschedparam(). Changing real-time policies may require CAP_SYS_NICE.
Copyability / Movability
Trivially copyable and movable (stores only a TID/handle).
Thread Safety
Methods are safe to call concurrently from different threads as long as the target thread still exists, but the class itself provides no internal synchronization.

Definition at line 668 of file thread_wrapper.hpp.

Member Typedef Documentation

◆ native_handle_type

Constructor & Destructor Documentation

◆ ThreadByNameView()

threadschedule::ThreadByNameView::ThreadByNameView ( const std::string & name)
inlineexplicit

Definition at line 677 of file thread_wrapper.hpp.

Member Function Documentation

◆ found()

auto threadschedule::ThreadByNameView::found ( ) const -> bool
inlinenodiscardnoexcept

◆ get_name()

auto threadschedule::ThreadByNameView::get_name ( ) const -> std::optional<std::string>
inlinenodiscard

Definition at line 740 of file thread_wrapper.hpp.

References found().

◆ native_handle()

auto threadschedule::ThreadByNameView::native_handle ( ) const -> native_handle_type
inlinenodiscardnoexcept

Definition at line 759 of file thread_wrapper.hpp.

◆ set_affinity()

auto threadschedule::ThreadByNameView::set_affinity ( ThreadAffinity const & affinity) const -> expected<void, std::error_code>
inlinenodiscard

Definition at line 787 of file thread_wrapper.hpp.

References threadschedule::detail::apply_affinity(), and found().

◆ set_name()

auto threadschedule::ThreadByNameView::set_name ( std::string const & name) const -> expected<void, std::error_code>
inlinenodiscard

Definition at line 719 of file thread_wrapper.hpp.

References found().

◆ set_priority()

auto threadschedule::ThreadByNameView::set_priority ( ThreadPriority priority) const -> expected<void, std::error_code>
inlinenodiscard

Definition at line 764 of file thread_wrapper.hpp.

References threadschedule::detail::apply_priority(), and found().

◆ set_scheduling_policy()

auto threadschedule::ThreadByNameView::set_scheduling_policy ( SchedulingPolicy policy,
ThreadPriority priority ) const -> expected<void, std::error_code>
inlinenodiscard

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