Skip to content

Commit 9c123d1

Browse files
committed
Race condition in resume_foreground(DispatcherQueue)
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.
1 parent ae03783 commit 9c123d1

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

strings/base_coroutine_system.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ WINRT_EXPORT namespace winrt
2525

2626
bool await_suspend(std::experimental::coroutine_handle<> handle)
2727
{
28-
m_queued = m_dispatcher.TryEnqueue(m_priority, [handle]
28+
return m_dispatcher.TryEnqueue(m_priority, [handle, this]
2929
{
30+
m_queued = true;
3031
handle();
3132
});
32-
33-
return m_queued;
3433
}
3534

3635
private:
37-
3836
Windows::System::DispatcherQueue const& m_dispatcher;
3937
Windows::System::DispatcherQueuePriority const m_priority;
4038
bool m_queued{};

0 commit comments

Comments
 (0)