Boost logo

Boost Users :

Subject: [Boost-users] [ASIO] Deadlock during static destruction
From: Dan Eaton (daniel.eaton_at_[hidden])
Date: 2009-05-27 13:57:25


Hello,

I'm using boost::asio on WinXP64, with boost 1.39. My app is deadlocking during destruction of a static object that has an io_service member variable.

If I explicitly delete the static object, no deadlock occurs. The static object is actually a shared_pointer, which points to the object I mentioned above. So at exit, assuming I haven't explicitly deleted the object, once the reference count reaches zero, delete is called, and the process deadlocks.

The offending piece of code appears to be in win_thread.hpp:143.
  void join()
  {
    ::WaitForSingleObject(exit_event_, INFINITE);
    ::CloseHandle(exit_event_);
    if (terminate_threads())
    {
      ::TerminateThread(thread_, 0);
    }
    else
    {
      ::QueueUserAPC(apc_function, thread_, 0);
      ::WaitForSingleObject(thread_, INFINITE);
    }
  }

It is blocked at ::WaitForSingleObject(exit_event_, INFINITE);

(This is as a result of the destruction of the io_service member).

In case it's significant, the io_service object is used to establish several socket connections (to and from remote hosts), some of which are through socket.connect, and others through socket.connect_async.

Thanks!
Danny



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