CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
Thread Class Referencefinal

Single thread of execution. More...

#include <cc/Thread>

Inheritance diagram for Thread:

Public Member Functions

 Thread ()=default
 Create a null thread.
 
 Thread (Function< void()> &&f, long stackSize=-1)
 Create a new thread.
 
void start ()
 Start the thread.
 
bool started () const
 Tell if the thread has been started.
 
void wait ()
 Wait for the thread to finish its execution.
 
void kill (Signal signal)
 Send a signal to the thread.
 
bool isRunning () const
 Check if the thread is still running.
 
void setName (const char *name)
 Set the thread's name for debugging
 
 operator bool () const
 Check if this is a non-null thread.
 
- Public Member Functions inherited from Object
 Object ()=default
 Create a null object.
 
 operator bool () const
 Check if this is a non-null object.
 
bool isNull () const
 Check if this is a null object.
 
template<class T >
bool is () const
 Check if this object is of type T.
 
template<class T >
as () const
 Cast this object to type T.
 
bool isWeak () const
 Check if the underlying object reference is weak.
 
bool operator== (const Object &other) const
 Equality operator.
 
std::strong_ordering operator<=> (const Object &other) const
 Ordering operator.
 
long useCount () const
 Reference count.
 

Static Public Member Functions

static uint64_t id ()
 Get an unique ID indentifying the calling thread.
 
static void sleep (double duration)
 Suspend execution of the current thread for duration seconds.
 
static void sleepUntil (double time)
 Suspend execution of the current thread until time.
 
static void blockSignals (const SignalSet &set)
 Block signals of given set.
 
static void unblockSignals (const SignalSet &set)
 Unblock signals of given set.
 
static SignalSet signalMask ()
 Query the currently active signal mask.
 
static int getMinPriority (SchedulingPolicy policy)
 Get minimum priority level supported by the sytem under giving scheduling policy.
 
static int getMaxPriority (SchedulingPolicy policy)
 Get maximum priority level supported by the sytem under giving scheduling policy.
 
static void setSchedulingPolicy (SchedulingPolicy policy, int priority=0)
 Set scheduling policy of the calling thread
 

Additional Inherited Members

- Protected Member Functions inherited from Object
template<class T >
weak () const
 
template<class T >
void initOnce ()
 Create the object state when called the first time.
 
template<class T >
void initOncePerThread ()
 Create a distinct object state for each thread when called the first time in that thread.
 
 Object (State *newState)
 Initialize object with newState.
 
 Object (State *state, Alias)
 
 Object (State *state, Weak)
 
Objectoperator= (std::nullptr_t)
 
- Static Protected Member Functions inherited from Object
template<class T >
static T alias (const State *state)
 Create an alias object for the given state.
 
template<class T >
static T weak (const State *state)
 
- Protected Attributes inherited from Object
Handle< Stateme
 Internal object state
 

Detailed Description

Single thread of execution.

See also
System::concurrency()
Todo
simplify to autostart and remove start()/started()

Constructor & Destructor Documentation

◆ Thread() [1/2]

Thread ( )
default

Create a null thread.

◆ Thread() [2/2]

Thread ( Function< void()> && f,
long stackSize = -1 )
explicit

Create a new thread.

Parameters
fEntry point for thread execution
stackSizeSize of stack to allocate for the new thread (-1 for system default)

Member Function Documentation

◆ start()

void start ( )

Start the thread.

◆ started()

bool started ( ) const

Tell if the thread has been started.

Note
It is safe to invoke this method on a null thread, in which case it returns false.

◆ wait()

void wait ( )

Wait for the thread to finish its execution.

◆ kill()

void kill ( Signal signal)

Send a signal to the thread.

◆ isRunning()

bool isRunning ( ) const

Check if the thread is still running.

◆ setName()

void setName ( const char * name)

Set the thread's name for debugging

◆ operator bool()

operator bool ( ) const
explicit

Check if this is a non-null thread.

◆ id()

uint64_t id ( )
static

Get an unique ID indentifying the calling thread.

◆ sleep()

void sleep ( double duration)
static

Suspend execution of the current thread for duration seconds.

◆ sleepUntil()

void sleepUntil ( double time)
static

Suspend execution of the current thread until time.

See also
System::now()

◆ blockSignals()

void blockSignals ( const SignalSet & set)
static

Block signals of given set.

◆ unblockSignals()

void unblockSignals ( const SignalSet & set)
static

Unblock signals of given set.

◆ signalMask()

SignalSet signalMask ( )
static

Query the currently active signal mask.

◆ getMinPriority()

int getMinPriority ( SchedulingPolicy policy)
static

Get minimum priority level supported by the sytem under giving scheduling policy.

◆ getMaxPriority()

int getMaxPriority ( SchedulingPolicy policy)
static

Get maximum priority level supported by the sytem under giving scheduling policy.

◆ setSchedulingPolicy()

void setSchedulingPolicy ( SchedulingPolicy policy,
int priority = 0 )
static

Set scheduling policy of the calling thread