Hello, i have timer implemented with boost (144 -> newest lib). This timer is started within a boos thread. The timer also starts a thread in which an io_service hosts deadline timer until thread is terminated. so a continuous timer. The boost thread which needs the timer is create from within DLL.
The DLL ExitInstance function is called, when the hosting App. unloads the DLL. The ExitInstance function stops the thread and before timer. But the io_service destruction in my timer never returns, so the app hangs.
This happens NOT, when i am able to call a Dispose Function before ExitInstance is called. However, some application loading my DLL, give not the chance to call this expose function.
Anyone know, how to work around this problem ?
Here is the code of my timer core. It is the thread which restarts the service until thread is stopped. The thread get's stopped by setting _stop flag and setting deadlime timer to 1 ms in future. summary: hangs when within Dll::ExitInstance destructed. Hangs not, if destrcuted before Dll::ExitInstance Thank you
void tcTimerThread::timerLoop(void)
{
_running=true;
/// create asynch service
_io_service = new boost::asio::io_service;
/// create timer
_pTimer = new boost::asio::deadline_timer(*_io_service);
while(_stop==false)
{
_pTimer->expires_from_now(boost::posix_time::milliseconds(_delay));
/// bind timer event function
_pTimer->async_wait(boost::bind(&tcTimerThread::timerEvent,this,boost::asio::placeholders::error));
try
{
if(_stop==false)
{
/// reset async
_io_service->reset();
/// wait for timer event
_io_service->run();
}
}
catch(...)
{
}
}
try
{
_io_service->stop();
delete _pTimer;
delete _io_service;
}
catch(...)
{
}
_running=false;
}