
Hi, I'm sorry if this is not a question specifically about ASIO, but I need a suggestion.. I have a library that can be built like a Dynamic or static. Inside I have the following code: ---------------------------------------------------------- // Main io_service static boost::asio::io_service io_service; static boost::scoped_ptrboost::thread io_service_thread; static boost::asio::io_service::work work(io_service); static bool thread_started; EXTERN_C EUROATLIB_API MyObjHandl CALL GetMyObj() { if (!thread_started) { try { // run the IO service as a separate thread io_service_thread.reset(new boost::thread( boost::bind(&boost::asio::io_service::run, &io_service) )); thread_started = !thread_started; } catch (boost::thread_resource_error e) { // Failed to create the new thread return 0; } } // create the new object return new MyObj(io_service); }; ---------------------------------------------------------- Ok, now I need a way to stop the io_service thread when all MyObj are destroyed. In the clients I use: boost::scoped_ptr<MyObj> _devMyObj( GetMyObj() ); How can I accomplish this in a right way? Thanks, Daniele.