quote:
Original post by James Trotter
Take a look at flipcode. They have good tutorials on multithreading.
Yes they do...his example uses CreateThread() which underlying uses AfxBeginThread.

It''s not easy, but it''s cool.
- sighuh?
quote:
Original post by James Trotter
Take a look at flipcode. They have good tutorials on multithreading.
#pragma once#include <process.h>enum THREAD_PRIORITY{ TP_IDLE, TP_LOW, TP_NORMAL, TP_HIGH, TP_REALTIME};class CThread{public: CThread(enum THREAD_PRIORITY priority = TP_NORMAL); virtual ~CThread(void); bool threadActive(); void pause(); void resume(); void start(); void changePriority(enum THREAD_PRIORITY priority);protected: virtual void process()=0;private: static void entry(void * ptr); void terminate(void); void * threadHandle; bool paused; bool threadStarted; int threadPriority;};
#include "stdafx.h"#include "thread.h"CThread::CThread(enum THREAD_PRIORITY priority) : threadHandle(0), paused(0), threadPriority(0), threadStarted(0){ changePriority(priority);} void CThread::changePriority(enum THREAD_PRIORITY priority){ switch(priority) { case TP_IDLE: threadPriority=-15; break; case TP_LOW: threadPriority=-1; break; case TP_NORMAL: threadPriority=0; break; case TP_HIGH: threadPriority=1; break; case TP_REALTIME: threadPriority=2; break; } if (threadStarted) SetThreadPriority(threadHandle,threadPriority);}void CThread::start(){ if (threadStarted) return; threadStarted=true; threadHandle=(void*)_beginthread(entry,0,(void*)this); SetThreadPriority(threadHandle,threadPriority);}CThread::~CThread(void){ terminate();}void CThread::entry(void * ptr){ CThread * thread=(CThread*)ptr; thread->process(); thread->terminate();}void CThread::terminate(void){ if (threadHandle) TerminateThread(threadHandle,0); threadHandle=0;}bool CThread::threadActive(){ return threadHandle!=0;}void CThread::pause(){ if (paused || threadActive()) return; SuspendThread(threadHandle); paused=true;}void CThread::resume(){ if (!paused || threadActive()) return; ResumeThread(threadHandle); paused=false;}
void CThread::entry(void * ptr){ CThread * thread=(CThread*)ptr; thread->process(); thread->threadHandle=0; _endthread();}void CThread::terminate(void){ if (threadHandle) { threadHandle=0; TerminateThread(threadHandle,0); }}