lisoft
November 29th, 2004, 06:43 AM
I wrote two threads:
// thread_one:
{
//...
hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
//...
// do sth
// Some times call:
AfxBeginThread(thread_two, this);
//...
//...
// some code must wait if thread_two running
{
WaitForSingleObject(hEvent,INFINIT);
//continue to do sth if thread_two finished
}
}
// thread_two:
{
ResetEvent(hEvent); //to make sure hEvent is nosignaled
// do sth
SetEvent(hEvent);
}
I want the code in thread_one after WaitForSingleObject wait for thread_two finished if it is running.
But the fact is thread_one wait at WaitForSingleObject for ever and thread_two was also suspended when thread_one is waiting.
Need your help
Thanks!
// thread_one:
{
//...
hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
//...
// do sth
// Some times call:
AfxBeginThread(thread_two, this);
//...
//...
// some code must wait if thread_two running
{
WaitForSingleObject(hEvent,INFINIT);
//continue to do sth if thread_two finished
}
}
// thread_two:
{
ResetEvent(hEvent); //to make sure hEvent is nosignaled
// do sth
SetEvent(hEvent);
}
I want the code in thread_one after WaitForSingleObject wait for thread_two finished if it is running.
But the fact is thread_one wait at WaitForSingleObject for ever and thread_two was also suspended when thread_one is waiting.
Need your help
Thanks!