Common C++ Multithreading class 
Author Message
 Common C++ Multithreading class

I'm trying to create a Common Worker thread class, where I can derive from
it, creating my own function that implements the functionality and hey
presto. Perfect world??? But I'm having real trouble due the function
needing to be static.  Here's what I've got so far

// CThread allows the user to override the RunThread() function and insert
the processing

class CThread {
public:
 virtual DWORD RunThread();
 inline static DWORD WINAPI ThreadProc(LPVOID parameter) {
  return ((CThread*)parameter)->RunThread();
 }

Quote:
};

// CWorkerThread - Implements the Worker Thread creation and control, used
in conjunction
// with an instance of CThread.

class CWorkerThread : public CObject {
public:
 HANDLE   hThread;
 DWORD   dwThreadID;
 CThread   *pThread;
 inline CWorkerThread() {
  hThread = ::CreateThread(NULL, 0, CThread::ThreadProc, &pThread, 0,
&dwThreadID);
 }

Quote:
};

Then... if i did

// TESTING
class CMyThread : public CThread {
 DWORD RunThread();

Quote:
};

class CListener : public CWorkerThread {
public:

Quote:
};

DWORD CMyThread::RunThread()
{
 return (0);

Quote:
}

and create an instance of CMyThread everything would work------NOT!.  My
inexperience is showing but I would really appreciate an answer.

MarkM



Tue, 10 Oct 2000 03:00:00 GMT  
 Common C++ Multithreading class

Hi Mark,
I have a program that uses MFC threads. The Threads are
done as self contained classes.  you download it at
http://www.{*filter*}enet.net/~fforest/mycode.html

Hope it helps
Fred

Quote:

>I'm trying to create a Common Worker thread class, where I can derive from
>it, creating my own function that implements the functionality and hey
>presto. Perfect world??? But I'm having real trouble due the function
>needing to be static.  Here's what I've got so far

>// CThread allows the user to override the RunThread() function and insert
>the processing

>class CThread {
>public:
> virtual DWORD RunThread();
> inline static DWORD WINAPI ThreadProc(LPVOID parameter) {
>  return ((CThread*)parameter)->RunThread();
> }
>};

>// CWorkerThread - Implements the Worker Thread creation and control, used
>in conjunction
>// with an instance of CThread.

>class CWorkerThread : public CObject {
>public:
> HANDLE   hThread;
> DWORD   dwThreadID;
> CThread   *pThread;
> inline CWorkerThread() {
>  hThread = ::CreateThread(NULL, 0, CThread::ThreadProc, &pThread, 0,
>&dwThreadID);
> }
>};

>Then... if i did

>// TESTING
>class CMyThread : public CThread {
> DWORD RunThread();
>};

>class CListener : public CWorkerThread {
>public:
>};

>DWORD CMyThread::RunThread()
>{
> return (0);
>}

>and create an instance of CMyThread everything would work------NOT!.  My
>inexperience is showing but I would really appreciate an answer.

>MarkM



Wed, 11 Oct 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Common multithreading class

2. STL + ansi string class + multithreading

3. MultiThreading with CView-derived classes

4. Multithreading with the CView-derived classes

5. Multithreading with the CView-derived classes

6. Class form common constants...CRLF..

7. Debugging over a common class - trouble

8. Problems inheriting from a common CDialog derived class

9. CArray of different classes derived from common base

10. Common Dialog Class

11. Need Help creating a common Form View Class.

12. Make Folder Common Dialog Class

 

 
Powered by phpBB® Forum Software