From c952097dc65ac9c3715518e44855cab2d5a7ca93 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Tue, 27 Apr 2021 02:50:46 +0000 Subject: [PATCH] Remove incorrect ASSERT in ~AsyncWaitableEvent This patch removes an incorrect ASSERT(IsComplete()) in the destructor of AsyncWaitableEvent because when the destructor of AsyncWaitableEvent is called, the async task attached to mFuture may not be completed and the status of mFuture may not be 'ready'. In fact in C++14 we can always guarantee the attached async task is completed after the destruction of mFuture. BUG=dawn:529 Change-Id: I2f28246beb025a0d39dd432a404c0b04aed17249 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/48900 Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng Commit-Queue: Jiawei Shao --- src/dawn_platform/WorkerThread.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dawn_platform/WorkerThread.cpp b/src/dawn_platform/WorkerThread.cpp index 64d09f153a..7be4c3a63e 100644 --- a/src/dawn_platform/WorkerThread.cpp +++ b/src/dawn_platform/WorkerThread.cpp @@ -25,9 +25,6 @@ namespace { explicit AsyncWaitableEvent(std::function func) { mFuture = std::async(std::launch::async, func); } - virtual ~AsyncWaitableEvent() override { - ASSERT(IsComplete()); - } void Wait() override { ASSERT(mFuture.valid()); mFuture.wait(); @@ -38,6 +35,11 @@ namespace { } private: + // It is safe not to call Wait() in the destructor of AsyncWaitableEvent because since + // C++14 the destructor of std::future will always be blocked until its state becomes + // std::future_status::ready when it was created by a call of std::async and it is the + // last reference to the shared state. + // See https://en.cppreference.com/w/cpp/thread/future/~future for more details. std::future mFuture; };