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

Raymond Chen

Raymond

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!

0 comments

Comments are closed. Login to edit/delete your existing comments