![]() ![]() In a multithreaded program, the handlers for asynchronous operations should be synchronised if they access shared resources. By wrapping the handlers using the same boost::asio::strand, we are ensuring that they cannot execute concurrently. The strand::wrap() function returns a new handler that automatically dispatches its contained handler through the boost::asio::strand object. When initiating the asynchronous operations, each callback handler is wrapped using the boost::asio::strand object. Of course, the handlers may still execute concurrently with other handlers that were not dispatched through an boost::asio::strand, or were dispatched through a different boost::asio::strand object. This is guaranteed irrespective of the number of threads that are calling io_service::run(). In addition to initialising a pair of boost::asio::deadline_timer members, the constructor initialises the m_strand member, an object of type boost::asio::strand.Ī boost::asio::strand guarantees that, for those handlers that are dispatched through it, an executing handler will be allowed to complete before the next one is started. M_timer2.async_wait(m_strand.wrap(boost::bind(
0 Comments
Leave a Reply. |