boost::asio::io_service m_io_service;
boost::asio::io_service::work m_work(m_io_service);
m_io_service.run()
m_io_service.stop();
m_io_service.reset();
m_io_service.run(); //work object still used here or should I recreate a m_work object?
如果我停止io_service对象,然后再次启动它,是否需要将其重新绑定到工作对象?
答案 0 :(得分:2)
规范的方法是
optional<asio::io_service::work> m_work(asio::io_service::work(m_io_service));
或
shared_ptr<asio::io_service::work> m_work = make_shared<asio::io_service::work>(m_io_service);
因此,在这两种情况下,您都可以使用
发出“关闭服务的信号”m_work.reset();
而且,不,我认为你不需要重新绑定工作对象。工作对象不是实际的异步操作。它更像是一个refcount / lock