Reputation: 25799
I'm developing a network server based on Boost::Asio.
I have a boost::thread_group
of IO worker threads which I use to call boost::asio::io_service::run( )
When network activity occurs ASIO uses one of these worker threads to process the activity (eg. Accept or Receive).
My application then does some work, possibly some calculation, possibly some other IO (via boost) and possibly some database activity.
I'd like to know what the implications are of doing said work within these threads. Specifically:
io_service
any grief?And less specifically: any other issues I should be thinking about.
Upvotes: 0
Views: 677
Reputation: 24174
Does carrying out ( possibly significant work ) on the IO threads cause the io_service any grief?
It really depends what you mean by grief. Performing long running operations in a handler invoked by an io_service
can block additional handlers from being invoked by the io_service
. Consider the simplest example with a single thread invoking io_service::run()
. If the handler invoked by an asynchronous operation, say async_read()
then performs some database operations that could be long running, additional outstanding asynchronous operations will not have their handlers invoked until the long running operation is complete and the handler returns control to the io_service
.
This is typically mitigated by invoking io_service::run()
from multiple threads, and using a strand
to ensure exclusive access to handlers that used shared data. Though if all of your handlers perform some long running operations, you might need to investigate alternative designs.
Upvotes: 1