anyone here know how to do multi-threaded programming in C++?
it would be great if someone can show me a sample.![]()
here is what i got from a website,but i cannot make it work ....![]()
Code:class Thread { public: Thread(); int Start(void * arg); protected: int Run(void * arg); static void * EntryPoint(void*); virtual void Setup(); virtual void Execute(void*); void * Arg() const {return Arg_;} void Arg(void* a){Arg_ = a;} private: THREADID ThreadId_; void * Arg_; }; Thread::Thread() {} int Thread::Start(void * arg) { Arg(arg); // store user data int code = thread_create(Thread::EntryPoint, this, & ThreadId_); return code; } int Thread::Run(void * arg) { Setup(); Execute( arg ); } /*static */ void * Thread::EntryPoint(void * pthis) { Thread * pt = (Thread*)pthis; pthis->Run( Arg() ); } virtual void Thread::Setup() { // Do any setup here } virtual void Thread::Execute(void* arg) { // Your code goes here }



LinkBack URL
About LinkBacks




CornedBee