8#ifndef HPP_ALIB_THREADS_THREAD
9#define HPP_ALIB_THREADS_THREAD 1
16#include "alib/strings/astring.hpp"
23namespace alib {
namespace threads {
84 virtual void Run() = 0;
161 :
Thread( nullptr, pName ) {}
265 virtual void Start();
326 { std::this_thread::sleep_for( std::chrono::milliseconds( milliseconds ) ); }
333 { std::this_thread::sleep_for( std::chrono::microseconds( microseconds ) ); }
339 { std::this_thread::sleep_for( std::chrono::nanoseconds( nanoseconds ) ); }
344 static void Sleep (
const Ticks::Duration& duration )
345 { std::this_thread::sleep_for( duration.Export() ); }
350 static void Sleep (
const Ticks::Duration::TDuration& duration )
351 { std::this_thread::sleep_for( duration ); }
357 { std::this_thread::sleep_until( time.
Export() ); }
360#if ALIB_BOXING && !DOXYGEN
393#if ALIB_ENUMS && ALIB_BOXING
const TUnboxable Unbox() const
virtual ~Runnable()
Virtual destructor.
virtual ALIB_API void Start()
static void YieldToSystem()
ThreadID id
The id of the thread.
static Thread * GetCurrent()
virtual void SetName(const String &newName)
static void SleepUntil(const Ticks &time)
static void Sleep(const Ticks::Duration::TDuration &duration)
virtual ALIB_API ~Thread() override
virtual const CString GetName() const
@ Running
The thread's Run method is currently processed.
@ Started
Method Start was invoked but not running, yet.
@ Terminated
The thread is terminated.
Thread(const Thread &)=delete
Deleted copy constructor.
AString name
The name of the thread.
State state
Internal flag to indicate if the thread is alive.
std::thread * c11Thread
The internal C++ thread object.
static void SleepNanos(int64_t nanoseconds)
static ALIB_API Thread * GetMain()
ALIB_API Thread(const String &pName=EMPTY_STRING)
virtual void Run() override
static ALIB_API Thread * Get(std::thread::id nativeID)
static void SleepMicros(int64_t microseconds)
virtual ALIB_API void Join()
std::thread::id GetNativeID() const
std::thread::id nativeID
The internal C++ thread id.
static void SleepMillis(int milliseconds)
Runnable * runnable
The runnable to execute.
static void Sleep(const Ticks::Duration &duration)
TTimePoint Export() const
#define ALIB_ASSERT_MODULE(modulename)
#define ALIB_STRINGS_APPENDABLE_TYPE_N(TYPE)
#define ALIB_ENUMS_ASSIGN_RECORD(TEnum, TRecord)
#define ALIB_STRINGS_APPENDABLE_TYPE_W(TYPE)
void threadStart(Thread *thread)
static constexpr ThreadID UNDEFINED
This is a value that may be passed as a value indicating an undefined thread.
integer ThreadID
The ALib thread identifier type.
threads::Thread Thread
Type alias in namespace alib.
constexpr const String EMPTY_STRING
An empty string of the default character type.
lang::integer integer
Type alias in namespace alib.
threads::ThreadID ThreadID
Type to store thread identifiers.