Concurrent Programming 3/3
- For complex orchestration problems we quickly end up with asynchronous spaghetti code.
"It is more difficult to develop applications using asynchronous mechanisms due to the separation in time and space between operation initiation and completion" (
boost::asio docs)
- All asynchronous mechanisms suffer from this problem (message queues, callbacks, continuation passing, ...)
- Blocking operations (where the operation initiation and completion are localized in space) are much easier to work with, because we can apply our 'standard' sequential control flow structures to them:
if (waitforKeypress() == "q") ...; else ...;
display(doHttpGetRequest('http://bbc.com'));
print("countdown:");
for (var i=10; i>0; --i) {
wait(1000);
print(i);
}
- Unfortunately we cannot express parallel control flows in this way. We can only do one thing at a time.