Boost logo

Boost Users :

Subject: [Boost-users] boost::asio::io_service destructor never returns
From: custgmx.net (customer001_at_[hidden])
Date: 2010-09-17 17:52:43


Hello,

he 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

Code:

 

void tcTimerThread::timerLoop(void)

{

_running=true;

_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;

       /// !! never returns if called within ExitInstance of DLL;returns
always is called before ExitInstance of DLL
       delete _io_service;
    }
    catch(...)
    {
    }
    _running=false;

}

 



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net