Originally Posted by
MK27
Hmm, can you use that to cast to an object too? I presume so...FoundationThreadBase is a class, no?
Still think that thing with void* might be one of the single dumbest design choice I've ever heard of.
MK: FoundationThreadBase is an abstract base class I use (this is part of what will get mailed to you this weekend) to easily manage threads so basically all you need to do to create a thread is:
Code:
#include "foundationthread.hpp"
// making a thread is as simple as deriving a class from Foundation
// ThreadBase, providing a run() method, creating an instance of this
// derived class and call start()
class ThreadTest:public FoundationThreadBase
{
private:
public:
ThreadTest()
{
//MT
}
~ThreadTest()
{
//MT
}
virtual int Run(void *ptrArgs);
};
And then supplying a Run() method:
Code:
//********************************************
// Method:Run()
//
// Args:None
//
// Return:0 on success, -1 if fail
//
// Desc:Actual run routine for this thread
//********************************************
int ThreadTest::Run(void *ptrData)
{
int nResultCode = 0;
// supply the thread work functionality here...
return nResultCode;
}
Then in your main thread, to launch this it is as simple as:
Code:
ThreadTest myThread;
myThread.Start(false);
myThread.Join();
Note: this is still a work in progress but to me this has always been the simplest way to launch threads and manage them effectively. You will see the whole code-base later this weekend.