Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 26fd7d0

Browse files
authored
Fix flake by making thread ID tracking in CanPostTaskToAllNativeThreads thread safe. (#16081)
1 parent aab316c commit 26fd7d0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

shell/platform/embedder/tests/embedder_unittests.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,6 +3943,7 @@ TEST_F(EmbedderTest, CanPostTaskToAllNativeThreads) {
39433943
fml::CountDownLatch latch;
39443944

39453945
// Ensures that the expect number of distinct threads were serviced.
3946+
std::mutex thread_ids_mutex;
39463947
std::set<std::thread::id> thread_ids;
39473948

39483949
size_t platform_threads_count = 0;
@@ -3960,7 +3961,6 @@ TEST_F(EmbedderTest, CanPostTaskToAllNativeThreads) {
39603961
engine.get(),
39613962
[](FlutterNativeThreadType type, void* baton) {
39623963
auto captures = reinterpret_cast<Captures*>(baton);
3963-
39643964
switch (type) {
39653965
case kFlutterNativeThreadTypeRender:
39663966
captures->render_threads_count++;
@@ -3975,8 +3975,10 @@ TEST_F(EmbedderTest, CanPostTaskToAllNativeThreads) {
39753975
captures->platform_threads_count++;
39763976
break;
39773977
}
3978-
3979-
captures->thread_ids.insert(std::this_thread::get_id());
3978+
{
3979+
std::scoped_lock lock(captures->thread_ids_mutex);
3980+
captures->thread_ids.insert(std::this_thread::get_id());
3981+
}
39803982
captures->latch.CountDown();
39813983
},
39823984
&captures),

0 commit comments

Comments
 (0)