c++ - boost::asio socket sharing across threads in the HTTP Server 3 example -


i refer code in connection class of boost::asio http server 3 example http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio/example/http/server3/connection.cpp

it can seen each of async operations invoked on boost::asio::io_service::strand. ensures completion handlers not invoked concurrently. however, example server can run multiple threads calling io_service::run means of these threads used invoke handlers. of handlers in example invoke methods on boost::asio::ip::tcp::socket object. me, sharing socket object between threads (although not invoking methods on concurrently).

i can see no synchronization around socket calls question mechanism in place ensuring each thread has same view of state of socket object? documentation states unsafe share instance of boost::asio::ip::tcp::socket.

the documentation states tcp::socket not thread safe shared object.

i use accepted sgi stl definition of thread safety, is:

the sgi implementation of stl thread-safe in sense simultaneous accesses distinct containers safe, , simultaneous read accesses shared containers safe. if multiple threads access single container, , @ least 1 thread may potentially write, user responsible ensuring mutual exclusion between threads during container accesses.

the key word being simultaneous. so, using multiple threads access shared object fine long access not concurrent. aside, matters if 1 or more of threads writing shared object.

the state of socket object in process' memory space, shared between threads , therefore cannot inconsistent.

hope answers question!


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -