Game Development Reference
In-Depth Information
2.
Then, we declare the thread interface:
class iThread
{
public:
iThread::iThread():FThreadHandle( 0 ),
FPendingExit(false) {}
virtual ~iThread() {}
void Start();
void Exit( bool Wait );
bool IsPendingExit() const { return FPendingExit; };
protected:
virtual void Run() = 0;
3.
The entry point prototype differs for Windows and Android, but only in the return type:
#ifdef _WIN32
static unsigned int __stdcall EntryPoint( void* Ptr );
#else
static void* EntryPoint( void* Ptr );
#endif
native_thread_handle_t GetCurrentThread();
private:
volatile bool FPendingExit;
thread_handle_t FThreadHandle;
};
4.
A portable implementation of the iThread::Start() method is done the following
way:
void iThread::Start()
{
void* ThreadParam = reinterpret_cast<void*>( this );
#ifdef _WIN32
unsigned int ThreadID = 0;
FThreadHandle = ( uintptr_t )_beginthreadex( NULL, 0,
&ThreadStaticEntryPoint, ThreadParam, 0, &ThreadID );
#else
pthread_create( &FThreadHandle, NULL, ThreadStaticEntryPoint,
ThreadParam );
pthread_detach( FThreadHandle );
#endif
}
 
Search WWH ::




Custom Search