StormByte 3.0.0
C++26 foundation of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Safe::Thread Class Reference

Execution owned by Base. More...

#include <StormByte/safe/thread.hxx>

Classes

class  Id
 Identifier of an execution. More...

Public Types

using native_handle_type = std::uintptr_t
 Native handle as an integer.

Public Member Functions

 Thread () noexcept
 Not an execution.
template<class Callable, class... Args>
requires (!Detail::IsVoidFunction<std::decay_t<Callable>>::value)
STORMBYTE_FORCE_INLINE Thread (Callable &&callable, Args &&... args)
 Start callable in a Base-owned execution.
template<class... Args>
STORMBYTE_FORCE_INLINE Thread (Function< void(Args...)> function, Args &&... args)
 Start a void Function in a Base-owned execution.
 Thread (const Thread &)=delete
 Thread (Thread &&other) noexcept
 Take an execution.
 ~Thread () noexcept
 Destroy the handle.
Thread & operator= (const Thread &)=delete
Thread & operator= (Thread &&other) noexcept
 Take an execution.
void swap (Thread &other) noexcept
 Exchange two executions.
bool joinable () const noexcept
 Whether this object owns an execution.
void join ()
 Wait until the execution returns.
void detach ()
 Detach the execution.
Id get_id () const noexcept
 Identifier of the owned execution.
native_handle_type native_handle () noexcept
 Native handle as an integer.

Static Public Member Functions

static unsigned hardware_concurrency () noexcept
 Hint of concurrent executions.
static Id Calling () noexcept
 Identifier of the calling execution.

Detailed Description

Execution owned by Base.

Not an alias of std::thread. The native thread is started and joined in Base. Destroying a joinable thread terminates the process, as std::thread does. A UNIX execution has an 8 MiB stack. musl's default of 128 KiB is not used. Windows keeps the system default. A Function is stored by value and invoked with Call. The creator-module release stays with the function.

Member Typedef Documentation

◆ native_handle_type

Native handle as an integer.

Not a CRT thread type.

Constructor & Destructor Documentation

◆ Thread() [1/5]

StormByte::Safe::Thread::Thread ( )
inlinenoexcept

Not an execution.

◆ Thread() [2/5]

template<class Callable, class... Args>
requires (!Detail::IsVoidFunction<std::decay_t<Callable>>::value)
STORMBYTE_FORCE_INLINE StormByte::Safe::Thread::Thread ( Callable && callable,
Args &&... args )
inlineexplicit

Start callable in a Base-owned execution.

Template Parameters
CallableCallable. Invoked in the new execution. A Function uses the other constructor.
ArgsArgument types, decayed and stored before the execution starts.
Parameters
callableEntry.
argsArguments.
Exceptions
AllocationErrorThe execution or its state cannot be allocated.

◆ Thread() [3/5]

template<class... Args>
STORMBYTE_FORCE_INLINE StormByte::Safe::Thread::Thread ( Function< void(Args...)> function,
Args &&... args )
inlineexplicit

Start a void Function in a Base-owned execution.

Template Parameters
ArgsArgument types. Captured before the execution starts.
Parameters
functionCallback. Moved. Its release stays in the creator module.
argsArguments passed to Call.
Exceptions
AllocationErrorThe execution or its state cannot be allocated.

Status is not returned. A Base exception is caught in the execution.

◆ Thread() [4/5]

StormByte::Safe::Thread::Thread ( const Thread & )
delete

◆ Thread() [5/5]

StormByte::Safe::Thread::Thread ( Thread && other)
inlinenoexcept

Take an execution.

Parameters
otherSource. Left not joinable.

◆ ~Thread()

StormByte::Safe::Thread::~Thread ( )
inlinenoexcept

Destroy the handle.

A joinable execution terminates the process.

Member Function Documentation

◆ Calling()

Id StormByte::Safe::Thread::Calling ( )
inlinestaticnoexcept

Identifier of the calling execution.

Returns
Non-zero identifier.

◆ detach()

void StormByte::Safe::Thread::detach ( )
inline

Detach the execution.

Exceptions
ExceptionThe thread is not joinable.

◆ get_id()

Id StormByte::Safe::Thread::get_id ( ) const
inlinenoexcept

Identifier of the owned execution.

Returns
Zero identifier when this object is not joinable.

◆ hardware_concurrency()

unsigned StormByte::Safe::Thread::hardware_concurrency ( )
inlinestaticnoexcept

Hint of concurrent executions.

Returns
Zero when the hint is not available.

◆ join()

void StormByte::Safe::Thread::join ( )
inline

Wait until the execution returns.

Exceptions
ExceptionThe thread is not joinable.

◆ joinable()

bool StormByte::Safe::Thread::joinable ( ) const
inlinenoexcept

Whether this object owns an execution.

Returns
Joinable flag.

◆ native_handle()

native_handle_type StormByte::Safe::Thread::native_handle ( )
inlinenoexcept

Native handle as an integer.

Returns
Zero when this object is not joinable.

◆ operator=() [1/2]

Thread & StormByte::Safe::Thread::operator= ( const Thread & )
delete

◆ operator=() [2/2]

Thread & StormByte::Safe::Thread::operator= ( Thread && other)
inlinenoexcept

Take an execution.

A joinable destination terminates the process.

Parameters
otherSource. Left not joinable.
Returns
This thread.

◆ swap()

void StormByte::Safe::Thread::swap ( Thread & other)
inlinenoexcept

Exchange two executions.

Parameters
otherOther thread.

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