Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost-users][asio] timeout - is io_service.reset() safe with pool of threads?
From: Igor R (boost.lists_at_[hidden])
Date: 2009-01-31 10:46:37


>
> I'm implementing timeouts according to suggestion placed here
> http://lists.boost.org/Archives/boost/2007/04/120339.php
>
> because I still don't understand fully how io_service work I have
> question:
>
> is this way of implementation of timeout safe when I'm using pool of
> threads for one io_service?

That function assumes the io_service associated with your socket is
*stopped*, so it cannot run either in one thread or in multiple threads.
Note that it is an async. implementation for *synchronous* use, and when you
use sync. i/o you do not explicitly run io_service:

io_service io;
tcp::socket sock(io);
// open socket, define your buffer..., then:
read_with_timeout(sock, buffer);

But if you've already got an async. design, you don't need workarounds to
implement timeouts - just use deadline_timer in the straightforward way.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net