|
uLib
User mode C/C++ extended API library for Win32 programmers.
|
#include <uLib/Thread.h>
A simple wrapper for CreateThread().
When managing threads, I find it useful to have a thread know it's own handle and id
without external data. Thus a thread can f.ex close it's own handle when it is done.
SimpleThread is a convenient encapsulation of that concept.
Your thread function will always recieve a PSimpleThread on Start().
The Id member is used as the thread loop continuation flag, and Stop() sets it to zero
to indicate it is time to terminate the thread.
Note: SimpleThread is started with CreateThread(), not _beginthreadex(),
so be careful with CRTL functions.
Public Data | |
| PVOID | UserData |
| HANDLE | hThread |
| volatile DWORD | Id |
Public Functions | |
| SimpleThread () | |
| virtual | ~SimpleThread () |
| bool | Start (PTHREAD_START_ROUTINE ThrFunc, DWORD msYield=100) |
| bool | Stop (DWORD msWait=3000) |
| void | Close () |
| uLib::SimpleThread::SimpleThread | ( | ) |
Initialize the members.
Definition at line 31 of file Thread.cpp.
|
virtual |
Stop the thread, then destroy this.
Definition at line 35 of file Thread.cpp.
| bool uLib::SimpleThread::Start | ( | PTHREAD_START_ROUTINE | ThrFunc, |
| DWORD | msYield = 100 |
||
| ) |
Start the ThrFunc thread, and yield a little CPU time to give it a chance to initialize itself.
Definition at line 40 of file Thread.cpp.
| bool uLib::SimpleThread::Stop | ( | DWORD | msWait = 3000 | ) |
Tell the thread to stop by setting Id to zero, then wait a while for it to exit.
If it doesn't respond within msWait, kill it with TerminateThread().
Definition at line 54 of file Thread.cpp.
| void uLib::SimpleThread::Close | ( | ) |
Close the hThread, and clear the Id.
Definition at line 77 of file Thread.cpp.
| PVOID uLib::SimpleThread::UserData |
| volatile DWORD uLib::SimpleThread::Id |