
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@4 _ZwWaitForMultipleObjects@20 Worker Thread _TppWorkerThread@4 _NtWaitForWorkViaWorkerFactory@8 Worker Thread _TppWorkerThread@4 _NtWaitForWorkViaWorkerFactory@8 RPC Thread RPC Callback Thread _NtDelayExecution@8 Worker Thread _TppWorkerThread@4 _ZwWaitForSingleObject@12 ----------------------------------------------- ntdll.dll!_ZwWaitForSingleObject@12() ntdll.dll!_ZwWaitForSingleObject@12() kernel32.dll!_WaitForSingleObjectExImplementation@12() kernel32.dll!_WaitForSingleObject@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@16() ntdll.dll!_LdrpUnloadDll@8() ntdll.dll!_LdrUnloadDll@4() KernelBase.dll!_FreeLibrary@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@20() + 0x23 bytes user32.dll!_UserCallWinProcCheckWow@32() + 0xb7 bytes user32.dll!_SendMessageWorker@24() + 0x112 bytes user32.dll!_SendMessageA@16() + 0x4c bytes msvbvm60.dll!7294b5f6() msvbvm60.dll!7294a9cf() user32.dll!_NtUserPeekMessage@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@8() + 0x27 bytes ntdll.dll!__RtlUserThreadStart@8() + 0x1b bytes How can I solve? Regards, Daniele.
participants (1)
-
Daniele Barzotti