wangwangwangwang
December 22nd, 2004, 01:15 AM
i use a Event and a BOOL value to stop a thread, the thread is create with CreateThread, and a loop in the thread, when i create the thread,
i set the event object to non signal and the bool value to FALSE, when i click another button ,want to stop it, i set the bool value to TRUE to break the loop,then before quit the thread ,i set the Event. code such as below:
Button1Click:
m_bStop = FALSE;
ResetEvent(m_hEvent);
CreateThread(..);
In the Thead:(a loop in it)
{..
while (!m_bStop)
{
..
}
SetEvent(m_hEvent);
return 0;
}
Button2Click:
{
m_bStop = TRUE;
WaitForMultipleObjects(1,&m_hEventStop,TRUE,INFINITE);
..
}
but when i click the button 2, the application will be like deadlock,why?
and how to solve it?
thank you
}
i set the event object to non signal and the bool value to FALSE, when i click another button ,want to stop it, i set the bool value to TRUE to break the loop,then before quit the thread ,i set the Event. code such as below:
Button1Click:
m_bStop = FALSE;
ResetEvent(m_hEvent);
CreateThread(..);
In the Thead:(a loop in it)
{..
while (!m_bStop)
{
..
}
SetEvent(m_hEvent);
return 0;
}
Button2Click:
{
m_bStop = TRUE;
WaitForMultipleObjects(1,&m_hEventStop,TRUE,INFINITE);
..
}
but when i click the button 2, the application will be like deadlock,why?
and how to solve it?
thank you
}