The long-awaited std::thread
from the C++11 standard is not (yet) available in MinGW toolchain at the time of writing, and it does not possess capabilities necessary to adjust thread priorities, which is important for networking. So, we implement a simple class iThread
with the virtual method Run()
to allow portable multithreading in our code:
class iThread {
An internal LPriority
enumeration defines thread priority classes:
public: enum LPriority { Priority_Idle = 0, Priority_Lowest = 1, Priority_Low = 2, Priority_Normal = 3, Priority_High = 4, Priority_Highest = 5, Priority_TimeCritical = 6 };
The code for constructor and destructor is simple:
iThread(): FThreadHandle( 0 ), FPendingExit( false ) {} virtual ~iThread() {}
The Start()
method creates an OS-specific thread handle and starts execution. In all of the samples for this book, we do not need to postpone thread execution...