Marat Abrarov
2011-10-16 17:33:41 UTC
Hi, Chris and all users of Asio.
I have a small question about
virtual void boost::asio::io_service::service::shutdown_service().
Boost.Asio documentation says:
http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/reference/io_service__service/shutdown_service.html
But it is not enough accurate.
Actually (all released versions of Boost.Asio) io_service::service::shutdown_service is called only once - at
io_service::~io_service(). So, in general, there are no any concurrent operations related to any instance of
io_service::service (owned by destructing instance of io_service) already at this time (at
io_service::service::shutdown_service). In well-built architecture it cannot be (it have to be not) more than one thread
using the destructing instance of io_service. So we can assert that at the point of execution of
io_service::service::shutdown_service() till the end of lifetime of io_service::service there are no any concurrent
access to that instance of io_service::service.
Summing up: if we have flag (bool) shutdown_ at io_service::service and this flag is changed only at
io_service::service::shutdown_service (shutdown_ = true), so any other member function of io_service::service can check
shutdown_ without any defense from concurrent access (and without usage of interlocked* operations).
I use it at my project asio samples (ma::handler_storage_service class):
http://asio-samples.svn.sourceforge.net/viewvc/asio-samples/trunk/include/ma/handler_storage_service.hpp?revision=513&vi
ew=markup
Could it be described in Asio documentation? Or it cannot be guaranteed?
Regards,
Marat Abrarov.
I have a small question about
virtual void boost::asio::io_service::service::shutdown_service().
Boost.Asio documentation says:
http://www.boost.org/doc/libs/1_47_0/doc/html/boost_asio/reference/io_service__service/shutdown_service.html
But it is not enough accurate.
Actually (all released versions of Boost.Asio) io_service::service::shutdown_service is called only once - at
io_service::~io_service(). So, in general, there are no any concurrent operations related to any instance of
io_service::service (owned by destructing instance of io_service) already at this time (at
io_service::service::shutdown_service). In well-built architecture it cannot be (it have to be not) more than one thread
using the destructing instance of io_service. So we can assert that at the point of execution of
io_service::service::shutdown_service() till the end of lifetime of io_service::service there are no any concurrent
access to that instance of io_service::service.
Summing up: if we have flag (bool) shutdown_ at io_service::service and this flag is changed only at
io_service::service::shutdown_service (shutdown_ = true), so any other member function of io_service::service can check
shutdown_ without any defense from concurrent access (and without usage of interlocked* operations).
I use it at my project asio samples (ma::handler_storage_service class):
http://asio-samples.svn.sourceforge.net/viewvc/asio-samples/trunk/include/ma/handler_storage_service.hpp?revision=513&vi
ew=markup
Could it be described in Asio documentation? Or it cannot be guaranteed?
Regards,
Marat Abrarov.