One of the proposals for C++14 is Resumable Functions which gives C++ what is available in C# today with the async/await mechanisms. The basic idea is that a function can be paused while waiting for an asynchronous operation to complete. When the asynchronous operation completes the function can be resumed where it was paused. This is done in a non-blocking way so that the thread from which the resumable function was invoked will not be blocked.
It is not obvious to me in which context (thread) the function will be resumed. Will it be resumed by the thread from which the function was paused (this is how it is done in C# as I understand it) or does it use another thread?
If it is resumed by the thread from which it was paused, does the thread has to be put in some special state or will the scheduler handle this?
To quote from N3564:
After suspending, a resumable function may be resumed by the scheduling logic of the runtime and will eventually complete its logic, at which point it executes a return statement (explicit or implicit) and sets the function’s result value in the placeholder.
It should thus be noted that there is an asymmetry between the function’s observed behavior from the outside (caller) and the inside: the outside perspective is that function returns a value of type future at the first suspension point, while the inside perspective is that the function returns a value of type T via a return statement, functions returning future/shared_future behaving somewhat different still.
A resumable function may continue execution on another thread after resuming following a suspension of its execution.
This essentially means that
future<T>
does not have to be in a ready state).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With