Skip to content

Conversation

@oldnewthing
Copy link
Member

This fixes the problem of async_suspend accessing member variables after calling TryEnqueue.

It's possible for the lambda to run before control returns to the caller of TryEnqueue. This led to async_suspend accessing m_queued after it has already been destroyed by the lambda.

We make the lambda responsible for setting m_queued prior to resuming the coroutine. The lambda can infer that the task was queued by the fact that the lambda is running at all!

If the enqueue fails, then m_queued remains at its initial value of false.

This fixes #370

It's possible for the lambda to run before control
returns to the caller of TryEnqueue. This led to async_suspend
accessing m_queued after it has already been destroyed
by the lambda.

We make the lambda responsible for setting m_queued prior to
resuming the coroutine.  The lambda can infer that the task
was queued by the fact that the lambda is running at all!

If the enqueue fails, then m_queued remains at its initial
value of false.
Copy link
Collaborator

@kennykerr kennykerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Much simpler. 😉

@oldnewthing oldnewthing deleted the dispatcher-queued branch October 13, 2019 17:08
@oldnewthing oldnewthing restored the dispatcher-queued branch October 15, 2019 16:15
@oldnewthing oldnewthing reopened this Oct 15, 2019
@kennykerr kennykerr merged commit 49f0215 into microsoft:master Oct 15, 2019
@oldnewthing oldnewthing deleted the dispatcher-queued branch October 15, 2019 16:22
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.

Race condition in resume_foreground(DispatcherQueue)

3 participants