By Raymond Chen :
C++ coroutines: The problem of the DispatcherQueue task that runs too soon, part 1 | The Old New Thing | devblogs.microsoft.com
I was experiencing occasional crashes in C++/WinRT’s resume_foreground function when it tries to resume execution on a dispatcher queue. Here’s a simplified version of that function: auto resume_foreground(DispatcherQueue const& dispatcher) { struct awaitable { DispatcherQueue m_dispatcher; bool m_queued = false; bool await_ready() { return false;
more...
Article Raymond Chen CPP Dec 23, 2019 1  
C++ coroutines: The problem of the synchronous apartment-changing callback | The Old New Thing | devblogs.microsoft.com
Today is a puzzle you can you can try to solve with the information you’ve learned about C++ coroutines and C++/WinRT. C++/WinRT uses the IContext­Callback interface to remember the context that initiated a co_await operation, so it can resume execution in the original apartment when the co_await completes.
more...
Article Raymond Chen CPP Dec 21, 2019 1  
C++ coroutines: The co_await operator and the function search algorithm | The Old New Thing | devblogs.microsoft.com
So you’re following along Kenny Kerr’s blog and you get to the part where he uses co_await on a time duration: co_await 5s; so you try it: #include <chrono> using namespace std::chrono; winrt::IAsyncAction Delay10Seconds() { co_await 10s; co_return; } and you get the error message no callable ‘await_resume’
more...
Article Raymond Chen CPP Dec 20, 2019 1  
C++ coroutines: Defining the co_await operator | The Old New Thing | devblogs.microsoft.com
At the start of this series, I noted that there are three steps in obtaining an awaiter for an awaitable object. The first two were marked “We’re not read to talk about this yet.” Well, now we’re ready to talk about one of them.
more...
Article Raymond Chen CPP Dec 19, 2019 1  
C++ coroutines: no callable 'await_resume' function found for type | The Old New Thing | devblogs.microsoft.com
You try to co_await something and get the error message no callable ‘await_resume’ (or ‘await_ready’ or ‘await_suspend’) function found for type ‘Expression’ What does this mean? Recall how the compiler generates code for co_await:   calculate x obtain awaiter co_await if (!awaiter.await_ready()) { save state for resumption if (awaiter.await_suspend(handle)) { return to caller [Invoking the handle resumes execution here] } restore state after resumption } result = awaiter.await_resume();
more...
Article Raymond Chen CPP Dec 18, 2019 1  
C++ coroutines: Short-circuiting suspension, part 2 | The Old New Thing | devblogs.microsoft.com
There’s one last section of the outline of compiler code generation for co_await that is marked “We’re not ready to talk about this step yet.” Let’s talk about that step. Before suspending the coroutine, the compiler asks the awaiter’s await_ready method.
more...
Article Raymond Chen CPP Dec 17, 2019 2  
C++ coroutines: Short-circuiting suspension, part 1 | The Old New Thing | devblogs.microsoft.com
At the start of this series, I gave the basic idea for how the compiler generates code for co_await, but I left out some details for expository simplicity. There are some mysterious steps called “We’re not ready to talk about this step yet.”
more...
Article Raymond Chen CPP Dec 13, 2019 1  
C++ coroutines: Awaiting an IAsyncAction without preserving thread context | The Old New Thing | devblogs.microsoft.com
The C++/WinRT library provides an awaiter for Windows Runtime asynchronous activities. Those asynchronous activities are represented by IAsync­Action, IAsync­Operation, and progress versions of the above. The C++/WinRT-provided awaiter resumes execution of the caller in the same COM apartment that awaited the activity.
more...
Article Raymond Chen CPP Dec 12, 2019 1  
C++ coroutines: Framework interop | The Old New Thing | devblogs.microsoft.com
So far, we’ve been looking at the basics of awaitable objects. Even though we barely know anything beyond await_suspend, we already know enough to allow us to start diving deeper. It is frequently the case that you need your awaiter to interact with something outside the C++ standard library.
more...
Article Raymond Chen CPP Dec 11, 2019 1  
C++ coroutines: Constructible awaitable or function returning awaitable? | The Old New Thing | devblogs.microsoft.com
Last time, we learned how to create simple awaitable objects by creating a structure that implements the await_suspend method (and relies on suspend_always to do the coroutine paperwork for us). We can then construct the awaitable object and then co_await on it.
more...
Article Raymond Chen CPP Dec 10, 2019 1  
C++ coroutines: Getting started with awaitable objects – The Old New Thing | devblogs.microsoft.com
C++ coroutines: Getting started with awaitable objects – The Old New Thing
more...
Article Raymond Chen CPP Dec 09, 2019 1  
In C++/WinRT, what happens when I treat an IInspectable as or convert one to a bool – The Old New Thing | devblogs.microsoft.com
In C++/WinRT, what happens when I treat an IInspectable as or convert one to a bool – The Old New Thing
more...
Article Raymond Chen CPP Dec 06, 2019 1  

Featured Contributors

Raymond Chen
CPP ~   ..