threads and synchronization

N

Nils

Hi,
I have some problems with threads.
I have a class thats start a thread. After thread the class should wait
nutil the thread is finish. I tried it like this:
----------------------------------------------------------------------------
--------------------------------
void CGeo2View::blush:nInsertObjects()
{
.....

CGeo2View::c_threadFinish=false;
CWinThread *thread=AfxBeginThread(onInsertObjectsThread,vec,1,0,0,NULL);
while(CGeo2View::c_threadFinish==false)
{
;
}
.....
}
----------------------------------------------------------------------------
--------------------------------
}
UINT CGeo2View::blush:nInsertObjectsThread(LPVOID pPara)
{
....

CGeo2View::c_threadFinish=true;
return 1;
....
}
----------------------------------------------------------------------------
--------------------------------
But after the while-loop starts it never ends.
I thought the reason could be as followed:
When the thread tries to set c_threadFinish to true, the while-loop reads
the varibale, so the it never set to "true"
Is that right?

So I tried it with the CEvent - Class. But can't implement it.

Can anyone tell how it will work in the exampla above.

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top