#include <cthread.h>
Public Member Functions | |
CThread () | |
Constructor. Does not start the thread. | |
virtual | ~CThread () |
Destructor. If the thread is running, it will be stopped. | |
bool | start () |
bool | stop () |
bool | isRunning () |
void | makeLowPriority () |
virtual void | threadFunc ()=0 |
Static Public Member Functions | |
static void * | run (void *arg) |
Protected Attributes | |
bool | m_Terminate |
You'll probably find plenty of reading material on multithreaded programming on the internet.
The main advantage of this class over other multithreading APIs is that libProcTer uses it, so by using this class, you are 100% sure your threads are compatible with libProcTer threads. Also, it makes your multithreading code portable to all platforms supported by libProcTer.
If you still want to use another threading API: libProcter uses standard win32 threads on windows, and POSIX threads on all other platforms.
libProcTer::CThread::CThread | ( | ) |
Constructor. Does not start the thread.
virtual libProcTer::CThread::~CThread | ( | ) | [virtual] |
Destructor. If the thread is running, it will be stopped.
bool libProcTer::CThread::isRunning | ( | ) |
void libProcTer::CThread::makeLowPriority | ( | ) |
Assigns a low priority to the thread. This is only possible when the thread is running.
bool libProcTer::CThread::start | ( | ) |
Starts the thread. Returns false on failure.
bool libProcTer::CThread::stop | ( | ) |
Stops the thread. Returns false on failure. This function blocks until the thread finishes voluntarily.
virtual void libProcTer::CThread::threadFunc | ( | ) | [pure virtual] |
The main function of the thread. You should implement this method in your derived classes.
The thread stops when this function returns.
You can return whenever you want, but you should return as soon as m_Terminate becomes true. Therefore, your implementation of threadFunc should check the value of m_Terminate at regular intervals, and return as soon as it becomes true.
bool libProcTer::CThread::m_Terminate [protected] |
Indicates whether the thread should stop. threadFunc() should check this value at regular intervals, and return when it becomes true.