Boost logo

Boost Users :

Subject: [Boost-users] [asio] io_service hang on stop
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2011-01-18 11:06:50


Hi,

I designed a library to start a io_service background thread when the
first object is created (these objects use serial_port) and to terminate
it when the last object is destroyed.
This is the io_worker_thread:

void io_worker_thread(void)
{
  io_service.reset();
  io_service.run();

  p_work.reset();
  io_service.stop();
  thread_started = false;
};

All seems to work, when the last object is destroyed the
io_service.run() returns...but the calling application hang!
I noted that the win_thread::join() (in win_thread.ipp) is still running
and waiting on "::WaitForSingleObject(thread_, INFINITE);"

Follow I post the threads and the call stack when the application is ended:

-----------------------------------------------
Main Thread Main Thread
boost::asio::detail::win_thread::join

Worker Thread _threadstartex
`io_worker_thread'::`2'::com_init::~com_init

Worker Thread _threadstartex _endthreadex
Worker Thread _TppWaiterpThread_at_4 _ZwWaitForMultipleObjects_at_20
Worker Thread _TppWorkerThread_at_4 _NtWaitForWorkViaWorkerFactory_at_8
Worker Thread _TppWorkerThread_at_4 _NtWaitForWorkViaWorkerFactory_at_8
RPC Thread RPC Callback Thread _NtDelayExecution_at_8
Worker Thread _TppWorkerThread_at_4 _ZwWaitForSingleObject_at_12
-----------------------------------------------

ntdll.dll!_ZwWaitForSingleObject_at_12()
ntdll.dll!_ZwWaitForSingleObject_at_12()
kernel32.dll!_WaitForSingleObjectExImplementation_at_12()
kernel32.dll!_WaitForSingleObject_at_8()
AxEuroATLib_debug.dll!boost::asio::detail::win_thread::join()
AxEuroATLib_debug.dll!boost::asio::detail::win_iocp_io_service::shutdown_service()
AxEuroATLib_debug.dll!boost::asio::detail::service_registry::~service_registry()
AxEuroATLib_debug.dll!boost::asio::detail::service_registry::`scalar
deleting destructor'()
AxEuroATLib_debug.dll!boost::asio::io_service::~io_service()
AxEuroATLib_debug.dll!`dynamic atexit destructor for 'io_service''()
AxEuroATLib_debug.dll!_CRT_INIT(void * hDllHandle=0x5b880000, unsigned
long dwReason=0, void * lpreserved=0x00000000)
AxEuroATLib_debug.dll!__DllMainCRTStartup(void * hDllHandle=0x5b880000,
unsigned long dwReason=0, void * lpreserved=0x00000000)
AxEuroATLib_debug.dll!_DllMainCRTStartup(void * hDllHandle=0x5b880000,
unsigned long dwReason=0, void * lpreserved=0x00000000)
ntdll.dll!_LdrpCallInitRoutine_at_16()
ntdll.dll!_LdrpUnloadDll_at_8()
ntdll.dll!_LdrUnloadDll_at_4()
KernelBase.dll!_FreeLibrary_at_4()
ole32.dll!77229562()
[Frames below may be incorrect and/or missing, no symbols loaded for
ole32.dll]
   ole32.dll!77229593()
   ole32.dll!772295a7()
   ole32.dll!772298bf()
   ole32.dll!77229805()
   ole32.dll!77229a8c()
   msvbvm60.dll!7294b681()
   msvbvm60.dll!72946299()
   msvbvm60.dll!7294613e()
   user32.dll!_InternalCallWinProc_at_20() + 0x23 bytes
   user32.dll!_UserCallWinProcCheckWow_at_32() + 0xb7 bytes
   user32.dll!_SendMessageWorker_at_24() + 0x112 bytes
   user32.dll!_SendMessageA_at_16() + 0x4c bytes
   msvbvm60.dll!7294b5f6()
   msvbvm60.dll!7294a9cf()
   user32.dll!_NtUserPeekMessage_at_20() + 0x15 bytes
   msvbvm60.dll!7294a95c()
   msvbvm60.dll!7294a8e2()
   msvbvm60.dll!7294a6cf()
   msvbvm60.dll!7294a63f()
   msvbvm60.dll!7294a5e1()
   msvbvm60.dll!7294a51d()
   msvbvm60.dll!7294a4e8()
   msvbvm60.dll!72943644()
   EuroATLibTest.exe!___vbaS() + 0xa bytes BASIC
   ntdll.dll!___RtlUserThreadStart_at_8() + 0x27 bytes
   ntdll.dll!__RtlUserThreadStart_at_8() + 0x1b bytes

How can I solve?

Regards,
Daniele.


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