In article <lnpp57$oih$
1...@needham.csi.cam.ac.uk>,
Nick Maclaren <
nm...@cam.ac.uk> wrote:
>In article <
7b734302-3479-4bf7...@googlegroups.com>,
>Michael S <
already...@yahoo.com> wrote:
>>
>>Can you define in reasonably precise terms what you mean by
>>"asynchronous comms protocols" and "synchronous comms protocols"
>>or to point me to someone's else definition that you consider
>>adequate?
>
>No, unfortunately :-( But I can describe the properties.
So, read up on the languages go (async channel) and erlang. For
general programming, read up on futures or even aio,
http://man7.org/linux/man-pages/man7/aio.7.html to get a feel for the
different between sync and async.
I liked your description. I'd view it this way, async rules, as you
can build sync with async; but, if you only have sync, you're screwed.
sync just waits for the action to be done, async merely queues the
action up and returns, immediately.
For example, in:
int temp = get_temperature ();
calculate_pi ();
printf("The temp is %d", temp);
imagine that get_temperature hits up a web server with the temperature
in your city. Let's say the server takes 0.5 seconds to get the
temperature and 0.5 seconds to communicate it to you. Let's say the
calculate_pi takes 1 seconds. This program runs in 2 seconds then.
Now imagine:
future int temp = get_temperature ();
calculate_pi ();
printf("The temp is %d", temp);
The variable temp is a future for the temperature. The first line
runs in 0.0 seconds. The next line runes in 1 second, and the next
line runs in 0 seconds, for a total time of 1 second. This is 2x the
performance for 1 extra word.
Now, how is this so? The request is started asynchronously to get the
temperature and queued in the first line. The communications happens
as pi is being calculated, and by the time pi is finished, we will
have the answer back, and placed into temp for direct use. In:
future int temp = get_temperature ();
printf("The temp is %d", temp);
the first line runs in 0 seconds, and the evaluation of temp requires
1 second, and the rest of the line is 0 seconds, for a net total of 1
second. For completeness:
future int temp = get_temperature ();
printf("The temp is %d", temp);
calculate_pi ();
runs in 2 seconds. Futures are a way to make use of an async service
in a program that was written as a synchronous program so that one can
quickly and easily transition to an underlying async world and start
seeing the benefits of that, sooner without massive rewritting of that
code. The programming model is compatible with most people's
conceptions of how programming works, so it makes it easier to
transition to. C++ has futures in it, if you want to see them in the
context of a C style language.