[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: CriticalSection in VisaulC++ in C
>Q1. Does this tell me that _multi_threading and inheritance the
> OO way are "incompatible"?
The way I did it once was to make a class CThread that would spawn when
constructed. The constructor of the CThread class would create a thread
and pass a statically declared C function (declared statically in the
'thread.cpp' file). This C function would get the object's this pointer
as a parameter and simply would call this->run().
>From that moment the thread would be back into the object oriented world.
The object's destructor would (attempt) to kill the thread.
The following code is not tested, but illustrates the idea:
CThread( const void* parameters );
static LPTHREADPROC ThreadStarter( CThread *caller )
CThread::CThread( const void* parameters )
m_Parameters = parameters;
CreateThread(..., ..., ..., ThreadStarter, this, ... );
... whatever the thread should do
>Q2. Why does it have to be a "C-style function". Is Win32 a non-OO
Dr. Ir. J.P.E. Sunter
PO. Box 218
5600 MD Eindhoven