Re: Sockets in C++?
On Apr 12, 6:51 am, n...@animats.com (John Nagle) wrote:
Mathias Gaunard wrote:
On Apr 10, 8:56 pm, John Nagle <n...@animats.com> wrote:
Once you start using a callback-based framework, you have to do
everything that can delay via that framework. Otherwise you stall the
callback engine. So the introduction of a callback-based framework
determines the overall design of the program.
An obvious solution is to run the whole engine in its own thread.
However, doing so automatically would reduce the user's control, who
couldn't choose on which thread (or pool of threads) he wants to run
it on.
Then you have to address thread-safety issues. If you want
to change "asio" list of work to do, and it has its own thread, how and
what do you lock? "asio" would need a lock that's locked when
"asio" isn't in its waiting state. That doesn't seem to have been
addressed.
Part of that should be asio's problem, not the users. But you
do have to face the fact that you force threads down the user's
throat, whether he wants them or not, and that the user must
take into account that he doesn't know in what thread the
callback may be executed, which seriously limits his options,
and means that he suddenly has to worry about synchronizing
things. (Note that it can be very tricky, since the callback
may also be called in the same thread. At a moment when the
thread holds the locks needed. And that those locks are not
necessarily recursive.)
Personally, I'd rather expose the threading: make the io
blocking, and leave it up to the user to split it off into a
second thread if he needs non-blocking.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]