Lunchbox
1.16.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
|
Utility class to execute code in a separate execution thread. More...
#include <thread.h>
Public Types | |
enum | Affinity { NONE = 0, CORE = 1, SOCKET = -65536, SOCKET_MAX = -1024 } |
Enumeration values for thread affinity. More... | |
Public Member Functions | |
Thread () | |
Construct a new thread. More... | |
Thread (const Thread &from) | |
Copy constructor. More... | |
virtual | ~Thread () |
Destruct the thread. More... | |
virtual bool | start () |
Start the thread. More... | |
virtual bool | init () |
The init function for the child thread. More... | |
virtual void | run ()=0 |
The entry function for the child thread. More... | |
virtual void | exit () |
Exit the child thread immediately. More... | |
void | cancel () |
Cancel (stop) the child thread. More... | |
bool | join () |
Wait for the exit of the child thread. More... | |
bool | isStopped () const |
Return if the thread is stopped. More... | |
bool | isRunning () const |
Return if the thread is running. More... | |
bool | isCurrent () const |
Static Public Member Functions | |
static ThreadID | getSelfThreadID () |
static void | yield () |
static void | setName (const std::string &name) |
static void | setAffinity (const int32_t affinity) |
Friends | |
void | abort (bool) |
Utility class to execute code in a separate execution thread.
Example:
lunchbox::Thread::Thread | ( | ) |
Construct a new thread.
|
explicit |
Copy constructor.
|
virtual |
Destruct the thread.
void lunchbox::Thread::cancel | ( | ) |
Cancel (stop) the child thread.
This function is not to be called from the child thread.
|
virtual |
Exit the child thread immediately.
This function does not return. It is only to be called from the child thread.
|
static |
Referenced by init().
|
inlinevirtual |
The init function for the child thread.
The parent thread will not be unlocked before this function has been executed. If the thread initialization fails, that is, this method does return false, the thread will be stopped and the start() method will return false.
Definition at line 86 of file thread.h.
References lunchbox::exit(), getSelfThreadID(), and lunchbox::operator<<().
bool lunchbox::Thread::isCurrent | ( | ) | const |
bool lunchbox::Thread::isRunning | ( | ) | const |
Return if the thread is running.
Note that the thread may be neither running nor stopped if it is currently starting or stopping.
bool lunchbox::Thread::isStopped | ( | ) | const |
Return if the thread is stopped.
Note that the thread may be neither running nor stopped if it is currently starting or stopping.
bool lunchbox::Thread::join | ( | ) |
Wait for the exit of the child thread.
|
pure virtual |
The entry function for the child thread.
This method should contain the main execution routine for the thread and is called after a successful init().
|
virtual |