From 56592c500f73677fcaa005a8281c9ea1318fe9b8 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Fri, 1 May 2020 14:53:07 -0700 Subject: [PATCH] Fabric: Fixing `executeSynchronouslyOnSameThread_CAN_DEADLOCK` Summary: In D20551411 we (I) replaced `std::mutex` with `std::recursive_mutex` in `executeSynchronouslyOnSameThread_CAN_DEADLOCK` in order to support synchronous `RuntimeExecutor`. It turned out that the idea was cool but totally incorrect. Quite obviously, double locking recursive mutex on the same thread does nothing, so the whole setup does not work at all. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D21328072 fbshipit-source-id: 7f1f81de61c36adb167fe624ada3bd71913bdf7c --- ReactCommon/runtimeexecutor/ReactCommon/RuntimeExecutor.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ReactCommon/runtimeexecutor/ReactCommon/RuntimeExecutor.h b/ReactCommon/runtimeexecutor/ReactCommon/RuntimeExecutor.h index bdde3603e61..e01e2df41c1 100644 --- a/ReactCommon/runtimeexecutor/ReactCommon/RuntimeExecutor.h +++ b/ReactCommon/runtimeexecutor/ReactCommon/RuntimeExecutor.h @@ -78,12 +78,10 @@ inline static void executeSynchronouslyOnSameThread_CAN_DEADLOCK( std::function &&callback) noexcept { // Note: We need the third mutex to get back to the main thread before // the lambda is finished (because all mutexes are allocated on the stack). - // We use `recursive_mutex` here to not deadlock in case if a - // `RuntimeExecutor` executes the callback synchronously. - std::recursive_mutex mutex1; - std::recursive_mutex mutex2; - std::recursive_mutex mutex3; + std::mutex mutex1; + std::mutex mutex2; + std::mutex mutex3; mutex1.lock(); mutex2.lock();