class Thread : private NoCopy
Encapsulation of thread.
Destructor. Performs Detach - thread continues running.
bool Run(Function<void ()> cb, bool noshutdown = false)
Starts a new thread. If noshutdown is true, started thread is not meant to be aware of Shutdown system - basically it means that it does not affect thread counter.
static void Start(Function<void ()> cb, bool noshutdown = false)
Starts a thread and returns immediately (you cannot Wait for the thread to finish in this case). If noshutdown is true, started thread is not meant to be aware of Shutdown system - basically it means that it does not affect thread counter.
Detaches running thread from the Thread object. It means that thread continues running but is no longer controlled by Thread instance.
Waits for started thread to finish. ("join").
bool IsOpen() const
Thread represents an existing thread. Note that the thread can be already finished and not running anymore (calling to Wait in that case returns immediately).
Thread::Id GetId() const
Returns the system-unique id of thread.
HANDLE GetHandle() const [WIN32]
pthread_t GetHandle() const [POSIX]
Returns platform specific handle of thread.
static void Sleep(int ms)
Sleep for a given number of milliseconds.
static bool IsST()
No additional thread was started yet (only the main thread is running so far).
static bool IsMain()
Returns true if current thread is main.
static int GetCount()
Number of running threads.
static void ShutdownThreads()
Sets the "Shutdown" flag on, waits before all threads started without noshutdown true terminate, then sets flag off again. It is meant to be used together with IsShutdownThreads to terminate long running secondary service threads. Main thread calls ShutdownThreads, secondary threads test IsShutdownThreads and if true, exit.
static bool IsShutdownThreads()
True if ShutdownThreads is active. This is supposed to be tested by threads participating in shutdown system.
static void (*AtExit(void (*exitfn)()))()
Allow to install a function exitfn to be called at thread exit. Returns the pointer to function already installed or NULL, client code should call the already installed function (return value is not null)
static Thread::Id GetCurrentId()
Returns the system-unique id of calling thread.
bool Priority(int percent)
Sets the treads priority to percent (0 to 200). In reality, current implementation supports only 5 levels, 25%, 75%, 125%, 175% and more than 175%; last two levels require root privileges. Returns true if setting the priority was successful.