experimental

C++ coroutines: The problem of the DispatcherQueue task that runs too soon, part 4--Raymond Chen

The series continue.

C++ coroutines: The problem of the DispatcherQueue task that runs too soon, part 4

by Raymond Chen

From the article:

Last time, we made another attempt to fix a race condition in C++/WinRT’s resume_foreground(Dispatcher­Queue) function when it tries to resume execution on a dispatcher queue. We did this by having the queued task wait until await_suspend was finished before allowing the coroutine to resume, and we found a nice place to put the synchronization object, namely in the awaiter, but even with that fix, we introduced additional memory barriers into the hot code path.

But it turns out all this work was unnecessary. We just had to look at the problem a different way.

The purpose of storing the result of Try­Enqueue into m_queued is so that await_resume can report whether the lambda was queued or not. But we can infer that information another way: The fact that our lambda is running means that got got queued. Because if the lambda were not queued, then it would never have run in the first place...

C++ coroutines: The problem of the DispatcherQueue task that runs too soon, part 3--Raymond Chen

The series contine.

C++ coroutines: The problem of the DispatcherQueue task that runs too soon, part 3

by Raymond Chen

From the article:

Last time, we fixed a race condition in C++/WinRT’s resume_foreground(Dispatcher­Queue) function when it tries to resume execution on a dispatcher queue. We did this by having the queued task wait until await_suspend was finished before allowing the coroutine to resume. The hard part was finding a place to put the synchronization object, and we ended up putting it in the queued task’s lambda...

C++ coroutines: The co_await operator and the function search algorithm--Raymond Chen

The series continue.

C++ coroutines: The co_await operator and the function search algorithm

by Raymond Chen

From the article:

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’ function found for type ‘Expression’ where Expression=std::chrono::seconds