Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle when a task is co_awaited by multiple awaiters #127

Merged
merged 1 commit into from
Oct 17, 2022

Conversation

danvratil
Copy link
Owner

The old approach caused that the last awaiter to co_await a coroutine function has overwritten the reference to the previous (so that any previous awaiter would not be resumed when the coroutine function has finished) but at the same time the await_suspend() would return false, so that the awaiter would get resume again immediatelly. However, since the last awaiter has also been registered as the only awaiting coroutine, once the awaited coroutine has finished, the awaiter was resumed for the second time, even if not suspended, causing crashes or memory leaks.

This change makes TaskAwaiterBase::await_suspend() a void function, and stores awaiters as a list, so that they can all get resumed when the coroutine finishes.

The old approach caused that the last awaiter to co_await a coroutine
function has overwritten the reference to the previous (so that any
previous awaiter would not be resumed when the coroutine function has
finished) but at the same time the `await_suspend()` would return `false`,
so that the awaiter would get resume again immediatelly. However, since
the last awaiter has also been registered as the only awaiting coroutine,
once the awaited coroutine has finished, the awaiter was resumed for the
second time, even if not suspended, causing crashes or memory leaks.

This change makes `TaskAwaiterBase::await_suspend()` a void function,
and stores awaiters as a list, so that they can all get resumed when
the coroutine finishes.
@danvratil danvratil merged commit ba3a978 into main Oct 17, 2022
@danvratil danvratil deleted the bug/multiple-awaiters branch October 17, 2022 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant