I have a code like below
void CLogThread::run()
{
m_alive = True; //only place where m_alive (declared volatile) set to true
while (m_alive)
{
//logic here
}
}
void CLogThread::stop()
{
m_alive = False;
}
void CThreadManager::uninit() throw()
{
try
{
if (m_pLogThread != NULL)
{
m_pLogThread->stop();
(void)m_pLogThread->getThreadControl().join();
m_pLogThread->uninit();
m_pLogThread = NULL;
}
}
catch (...)
{
}
}
I am trying to exit the process gracefully. But the problem is very rarely i see that program hangs at join.
Thread is still active in infinite while loop. m_alive value is "true" even after stop is called (in stop its set to false). m_alive is declared as volatile.