A
Anju Maria
hi All,
I need your help with a random hang issue we are facing with our desktop application.
We have a thread implemented to call Beep and Sleep APIs in a loop. So we start the thread to call these and then after some time, we break the loop, waitforsingleobject with a timeout in the main thread and come out of the thread. Just before returning from the thread function, we call _endthreadex. There is a hang here. Now I dont know whether the _endthreadex is failing and how it is stopping the waitforsingleobject from signalling after the timeout. The code is implemented pretty much similar to what is documented as an example for _beginthreadex. As I said, it occurs very randomly and on few machines.
unsigned __stdcall SecondThreadFunc( void* pArguments )
{
printf( "In second thread...\n" );
while( m_iBeepMode == iBEEPON )
{
Beep(600, 100);
Sleep(100);
}
//I added a logging here, which gets logged in hang case.
_endthreadex( 0 );
return 0;
}
int main()
{
HANDLE hThread;
unsigned threadID;
printf( "Creating second thread...\n" );
// Create the second thread.
hThread = (HANDLE)_beginthreadex( NULL, 16384, &SecondThreadFunc, this, 0, &threadID );
// the below code is not exactly in the same method. We call it at a later time to stop the beep.
m_iBeepMode = BEEPOFF;
WaitForSingleObject( hThread, 10000 );
// Added a logging here, which doesn't get logged.
// Destroy the thread object.
CloseHandle( hThread );
}
Continue reading...
I need your help with a random hang issue we are facing with our desktop application.
We have a thread implemented to call Beep and Sleep APIs in a loop. So we start the thread to call these and then after some time, we break the loop, waitforsingleobject with a timeout in the main thread and come out of the thread. Just before returning from the thread function, we call _endthreadex. There is a hang here. Now I dont know whether the _endthreadex is failing and how it is stopping the waitforsingleobject from signalling after the timeout. The code is implemented pretty much similar to what is documented as an example for _beginthreadex. As I said, it occurs very randomly and on few machines.
unsigned __stdcall SecondThreadFunc( void* pArguments )
{
printf( "In second thread...\n" );
while( m_iBeepMode == iBEEPON )
{
Beep(600, 100);
Sleep(100);
}
//I added a logging here, which gets logged in hang case.
_endthreadex( 0 );
return 0;
}
int main()
{
HANDLE hThread;
unsigned threadID;
printf( "Creating second thread...\n" );
// Create the second thread.
hThread = (HANDLE)_beginthreadex( NULL, 16384, &SecondThreadFunc, this, 0, &threadID );
// the below code is not exactly in the same method. We call it at a later time to stop the beep.
m_iBeepMode = BEEPOFF;
WaitForSingleObject( hThread, 10000 );
// Added a logging here, which doesn't get logged.
// Destroy the thread object.
CloseHandle( hThread );
}
Continue reading...