Boost Users :
Subject: Re: [Boost-users] boost asio
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2017-10-17 22:22:20
On 17/10/2017 16:48, Sharma, Nishant wrote:
> I have created an Asynchronous TCP server and client and it works fine.
> Since it is asynchronous, it uses APIs like async_read, async_write etc..
> Is it possible that the same code be used to do synchronous
> communication which results in blocking any further task in the queue
> unless the current i/o task is complete ?
That kinda defeats the point of using asynchronous functions to begin
with. Blocking functions are the arch-nemesis of asynchronous code.
With asynchronous code, if you don't want to do something until the task
is complete, then don't start it until the completion callback is
called, and only have one operation "in flight" at any given moment.
If you want to have operations executing in parallel but merely want to
make sure that the handlers don't get called concurrently, then link
them to the same strand. (This is not necessary but not harmful when
only one thread is running the io_service.)
If you want to make sure that nothing happens in parallel and everything
blocks until it's done, then use synchronous calls instead. There's an
example for that too. Bear in mind that while this is simpler to code,
it's also less scalable.
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