
9 May
2009
9 May
'09
9:54 p.m.
I've looked through the examples and there is a lot of different potential choices to make and was looking to see if anyone could advise on an arrangement that would allow for using multiple threads but block as little as possible.
Lets assume you want to send data from the main thread, while your io_service is running in another thread. You can't access the socket object in a straightforward way from the main thread without potential race-condition, because it's being processed by io_service in another thread. What you can do instead is to bind the data to a functor and post it to io_service's thread (look at the io_service::post() method for details) - this way you don't need to explicitly lock anything.