Per-thread control handle for OS-level scheduling operations.
A ThreadControlBlock captures the native thread handle (pthread_t on Linux, a duplicated HANDLE on Windows) at construction time and exposes cross-platform methods to modify the thread's affinity, priority, scheduling policy, and OS-visible name.
- Creation
- Always use the static factory create_for_current_thread(). It must be called from the thread it will represent, because it snapshots
pthread_self() / GetCurrentThread().
- Ownership
- ThreadControlBlock is intended to be held via
std::shared_ptr so that the registry, the owning thread, and any observers can all share the same instance. The static factory already returns a shared_ptr.
- Thread safety
- The object is not copyable and not movable (identity type).
- All
set_* methods are safe to call from any thread – they operate on the stored native handle, not on thread-local state.
- Concurrent calls to different
set_* methods on the same instance are safe (each call is a single OS syscall on the stored handle).
- Platform notes
- Linux: stores
pthread_t obtained via pthread_self(). No resource is owned; the handle is valid for the lifetime of the thread.
- Windows: duplicates the pseudo-handle returned by
GetCurrentThread() into a real HANDLE with THREAD_SET_INFORMATION | THREAD_QUERY_INFORMATION rights. The duplicated handle is closed in the destructor.
- Caveats
- Do not construct directly; always use create_for_current_thread().
- On Linux,
set_name() enforces the 15-character POSIX limit and returns std::errc::invalid_argument if exceeded.
Definition at line 129 of file thread_registry.hpp.