9

C++ coroutines: Allowing the awaiter to be destroyed while suspended

 3 years ago
source link: https://devblogs.microsoft.com/oldnewthing/20210419-00/?p=105119
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

C++ coroutines: Allowing the awaiter to be destroyed while suspended

Raymond Chen

Raymond

April 19th, 2021

One issue that we dealt with when we created our co_await awaitable signal was the case of the awaiter being destroyed while suspended. We had been ignoring that problem in our coroutine promise, but we can’t keep our head in the sand forever. Let’s take a look around and see where we are.

And it turns out that getting rid of the reference count also fixes the problem of an awaiting coroutine being destroyed while suspended: If that happens, the promise_ptr in the awaiter is destructed, and that abandons the coroutine. This means that when the coroutine completes, it will see that nobody is awaiting and won’t try to resume a destroyed awaiting coroutine.

Procrastination pays off!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK