Skip to content

Commit 3fb965d

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
prevent deadlock in C++ Animated (#51697)
Summary: Pull Request resolved: #51697 changelog: [internal] as a general rule of thumb, do not call outside of your class when holding a mutex. It is easy to cause a deadlock because the outside code may end up trying to acquire the mutex down the stack, leading to deadlock. Here, it happens because `startRenderCallbackIfNeeded` may end up calling onRender and in onRender, we try to acquire the mutex again Reviewed By: javache Differential Revision: D75675465 fbshipit-source-id: 46168ee154a54ae5cccaa74728b41f027519db59
1 parent 366c892 commit 3fb965d

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/react-native/ReactCxxPlatform/react/renderer/animated/NativeAnimatedNodesManager.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ class NativeAnimatedNodesManager {
144144
bool commitProps();
145145

146146
void scheduleOnUI(UiTask&& task) {
147-
std::lock_guard<std::mutex> lock(uiTasksMutex_);
148-
operations_.push_back(std::move(task));
147+
{
148+
std::lock_guard<std::mutex> lock(uiTasksMutex_);
149+
operations_.push_back(std::move(task));
150+
}
149151

150152
// Whenever a batch is flushed to the UI thread, start the onRender
151153
// callbacks to guarantee they run at least once. E.g., to execute

0 commit comments

Comments
 (0)