Boost logo

Boost :

From: Gaurav.Jain_at_[hidden]
Date: 2007-05-02 08:48:41


Hi,

Christopher Kohlhoff <chris <at> kohlhoff.com> writes:

> I'm sure I've outlined this in another email somewhere, but I can't
find
> it right now. Anyway, the basic idea is as follows:
>
> - Create an io_service for each CPU.
>
> - Create an io_service::work object for each io_service to keep it
> running when it would otherwise have nothing else to do.
> - Spawn a thread for each io_service to call io_service::run().

> - Create a tcp::acceptor on one of the io_services.
>
> - Create your tcp::socket objects on any of the io_services, using
some
> sort of load balancing scheme to choose the io_service to use (e.g.
> round robin).
>
> - Ensure that all communication between io_services uses message
> passing, i.e. use io_service::post().
>
> The core of the work would probably happen in a handle_accept
> function(), e.g. using the Daytime.3 tutorial program as a starting
> point:
>
> void start_accept()
> {
> // ------> Load balance here <------
> tcp_connection::pointer new_connection =
> tcp_connection::create(choose_io_service());
>
> acceptor_.async_accept(new_connection->socket(),
> boost::bind(&tcp_server::handle_accept, this, new_connection,
> asio::placeholders::error));
> }
>
> void handle_accept(tcp_connection::pointer new_connection,
> const asio::error_code& error)
> {
> if (!error)
> {
> // ------> Use message passing here <------
> new_connection->socket().io_service().post(
> boost::bind(&tcp_connection::start, new_connection));
>
> start_accept();
> }
> }

Chris in one of your replies I get to know that to achieve the above one
can use a pool of io service object. Could you explain a bit about this?
What is this io service::work object. How I can use thread pool in
achieving the above? What should I have in my worker object structure of
the thread pool?

Regards
Gaurav

DISCLAIMER:
This message contains privileged and confidential information and is intended only for an individual named. If you are not the intended recipient, you should not disseminate, distribute, store, print, copy or deliver this message. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. E-mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete or contain viruses. The sender, therefore, does not accept liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission. If verification is required, please request a hard-copy version.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk