From ec873f14d7c95dce919834e7ccdd37bbfaaa6164 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Mon, 27 Jan 2020 17:34:56 -0800 Subject: [PATCH] Fix flake by making thread ID tracking in CanPostTaskToAllNativeThreads thread safe. (flutter/engine#16081) --- .../shell/platform/embedder/tests/embedder_unittests.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engine/src/flutter/shell/platform/embedder/tests/embedder_unittests.cc b/engine/src/flutter/shell/platform/embedder/tests/embedder_unittests.cc index 5dc4e442349..c11b5883e99 100644 --- a/engine/src/flutter/shell/platform/embedder/tests/embedder_unittests.cc +++ b/engine/src/flutter/shell/platform/embedder/tests/embedder_unittests.cc @@ -3943,6 +3943,7 @@ TEST_F(EmbedderTest, CanPostTaskToAllNativeThreads) { fml::CountDownLatch latch; // Ensures that the expect number of distinct threads were serviced. + std::mutex thread_ids_mutex; std::set thread_ids; size_t platform_threads_count = 0; @@ -3960,7 +3961,6 @@ TEST_F(EmbedderTest, CanPostTaskToAllNativeThreads) { engine.get(), [](FlutterNativeThreadType type, void* baton) { auto captures = reinterpret_cast(baton); - switch (type) { case kFlutterNativeThreadTypeRender: captures->render_threads_count++; @@ -3975,8 +3975,10 @@ TEST_F(EmbedderTest, CanPostTaskToAllNativeThreads) { captures->platform_threads_count++; break; } - - captures->thread_ids.insert(std::this_thread::get_id()); + { + std::scoped_lock lock(captures->thread_ids_mutex); + captures->thread_ids.insert(std::this_thread::get_id()); + } captures->latch.CountDown(); }, &captures),