From 2b231a05fddafce51aa05b4b2b42d1f96d5a1a22 Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 11 Jul 2023 16:18:48 -0700 Subject: [PATCH] Release the mutex in the CanCreateConcurrentMessageLoop test before waking the latch (flutter/engine#43574) If the wake happens while thread_ids_mutex is still held, then the test function may exit and destroy thread_ids_mutex before the pool thread task releases it. Fixes https://github.com/flutter/flutter/issues/130344 --- engine/src/flutter/fml/message_loop_unittests.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/fml/message_loop_unittests.cc b/engine/src/flutter/fml/message_loop_unittests.cc index 7b9d14df89..4faad1db3b 100644 --- a/engine/src/flutter/fml/message_loop_unittests.cc +++ b/engine/src/flutter/fml/message_loop_unittests.cc @@ -331,8 +331,10 @@ TEST(MessageLoop, CanCreateConcurrentMessageLoop) { task_runner->PostTask([&]() { std::this_thread::sleep_for(std::chrono::seconds(1)); std::cout << "Ran on thread: " << std::this_thread::get_id() << std::endl; - std::scoped_lock lock(thread_ids_mutex); - thread_ids.insert(std::this_thread::get_id()); + { + std::scoped_lock lock(thread_ids_mutex); + thread_ids.insert(std::this_thread::get_id()); + } latch.CountDown(); }); }