rstd 0.1.0
Loading...
Searching...
No Matches
rstd::thread::Thread Class Referenceexport
module rstd

A handle to a thread. More...

Inheritance diagram for rstd::thread::Thread:
rstd::WithTrait< Thread, clone::Clone >

Public Member Functions

auto id () const noexcept -> ThreadId
 Gets the thread's unique identifier.
 
auto name () const -> Option< ThreadNameString >
 Gets the thread's name as a string reference if available.
 
void unpark () const noexcept
 Atomically makes the handle's token available if it is not already.
 
void park () const
 Like the public park, but callable on any handle.
 
void park_timeout (rstd::time::Duration timeout) const
 Like the public park_timeout, but callable on any handle.
 
auto cname () const noexcept -> Option< ref< ffi::CStr > >
 Gets the C string representation of the thread name, if available.
 
- Public Member Functions inherited from rstd::WithTrait< Thread, clone::Clone >

Static Public Member Functions

static auto make (ThreadId id, Option< String > name) -> Thread
 Creates a new thread handle.
 

Detailed Description

A handle to a thread.

Threads are represented by the Thread type. Each thread has a unique ThreadId, an optional name, and a parker for blocking/unblocking.

Member Function Documentation

◆ name()

auto rstd::thread::Thread::name ( ) const -> Option<ThreadNameString>
inline

Gets the thread's name as a string reference if available.

Returns None if no name was set.

◆ park()

void rstd::thread::Thread::park ( ) const
inline

Like the public park, but callable on any handle.

Safety

May only be called from the thread to which this handle belongs.

◆ park_timeout()

void rstd::thread::Thread::park_timeout ( rstd::time::Duration timeout) const
inline

Like the public park_timeout, but callable on any handle.

Safety

May only be called from the thread to which this handle belongs.

◆ unpark()

void rstd::thread::Thread::unpark ( ) const
inlinenoexcept

Atomically makes the handle's token available if it is not already.

Every thread is equipped with some basic low-level blocking support, via the park() function and the unpark() method. These can be used as a more CPU-efficient implementation of a spinlock.


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