Skip to content

Use refcount to track when to destroy coroutine#239

Merged
danvratil merged 1 commit intomainfrom
ref-count
Sep 22, 2024
Merged

Use refcount to track when to destroy coroutine#239
danvratil merged 1 commit intomainfrom
ref-count

Conversation

@danvratil
Copy link
Collaborator

Instead of a single bool that tells us whether we can destroy the coroutine safely, we now use a ref-count and destroy the coroutine when the count drops to 0. Generally, a coroutine has ref count value of 2 - one is held by the coroutine itself (ensuring it's not deleted until it finishes) and one is held by QCoro::Task, ensuring we can access the coroutine state as long as the corresponding Task exists.

This also opens doors to future enhancements, like SharedTasks that can be safely co_awaited by multiple awaiters.

Instead of a single bool that tells us whether we can destroy the
coroutine safely, we now use a ref-count and destroy the coroutine
when the count drops to 0. Generally, a coroutine has ref count
value of 2 - one is held by the coroutine itself (ensuring it's not
deleted until it finishes) and one is held by QCoro::Task, ensuring
we can access the coroutine state as long as the corresponding Task
exists.

This also opens doors to future enhancements, like SharedTasks that
can be safely co_awaited by multiple awaiters.
@danvratil danvratil merged commit 7d56a64 into main Sep 22, 2024
@danvratil danvratil deleted the ref-count branch September 22, 2024 19:38
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.

1 participant