diff --git a/rtc_base/task_queue_win.cc b/rtc_base/task_queue_win.cc index dd825d2fdc..8c11b8764a 100644 --- a/rtc_base/task_queue_win.cc +++ b/rtc_base/task_queue_win.cc @@ -134,11 +134,15 @@ class MultimediaTimer { } void Cancel() { - ::ResetEvent(event_); if (timer_id_) { ::timeKillEvent(timer_id_); timer_id_ = 0; } + // Now that timer is killed and not able to set the event, reset the event. + // Doing it in opposite order is racy because event may be set between + // event was reset and timer is killed leaving MultimediaTimer in surprising + // state where both event is set and timer is canceled. + ::ResetEvent(event_); } HANDLE* event_for_wait() { return &event_; }