Re: [asio-users] thread safety and IO objects
Brought to you by:
chris_kohlhoff
From: Christopher K. <ch...@ko...> - 2008-05-30 00:24:26
|
Max M. wrote: > I'd have a few more questions on this subject. > > After running io_service::stop, can I safely assume none of the > threads is still executing a handler? No, stop() doesn't block. You have to use some other mechanism to wait for the threads to complete. > Given my current knowledge of Asio, If I wanted to be able to, say, > stop a tcp::acceptor without stopping the whole io_service, I'd > probably choose to have all handlers started off through a strand and > provide a special handler to call tcp::acceptor::stop. > I'd also take a similar approach to handle timeouts on socket operations. > > Is there a way to achieve the same results without resorting to a > strand, other than locking all accesses to the acceptor or the socket? How about only having a single thread call io_service::run? :) I can't think of anything else off the top of my head. Cheers, Chris |