As a followup and a concrete example, here's what C++ is competing against; this piece of C# code starts an asynchronous read of a file and waits for it to complete up to some timeout value; only platform facilities are used here (i.e., no external libraries).


How does ReadAsync complete? Executor? Thread? OS-callback? Don't know, don't care, it works. I have an idea of how to accomplish the same in C++, and it's not pleasant -- worker thread, promise/future, blocking queue and CancelSynchronousIO. Cannot even use std::async because CancelSynchronousIO needs a target thread ID.


            try {
                int bytesRead = 0;
                var operationStart = DateTime.Now;
                var vt = sourceFile.ReadAsync(writeTask.Data);
                if (vt.IsCompletedSuccessfully) {
                    bytesRead = vt.Result;
                }
                else {
                    var t = vt.AsTask();
                    if (!t.Wait(State.TransferTimeoutSeconds * 1000))
                        throw new AggregateException(new TimeoutException("Reader timed out."));
                    bytesRead = t.Result;
                }
                writeTask.Data = writeTask.Data.Slice(0, bytesRead);
                var operationDuration = (DateTime.Now - operationStart);
                volumeHealthReport.ReadStatistics.UpdateBandwidth(bytesRead, operationDuration);
                return bytesRead;
            }
            catch (AggregateException e) {
                if (e.InnerException != null) writeTask.ReaderException = e.InnerException;
                else writeTask.ReaderException = e;
                volumeHealthReport.ReadStatistics.IncrementErrorCount();
                return 0;
            }