fuchsia: Fix race in AtomicFlagTest.ReadFromDifferentThread
My understanding is:
- start thread
- post a BusyWaitUntilFlagSet to that thread which does:
- busy loop until for tested_flag is set (calling sched_yield())
- EXPECTs expected_after_flag to be set by then
- sets done_flag
- meanwhile on the main thread:
- sleep 20ms
- set expected_after_flag
- set tested_flag
- sleep 20ms
- assert that done_flag has been set
So, previously the test relied on the background thread winning the race
between being released from the busy loop and getting to set done_flag
vs. the main loop getting from setting the tested_flag, sleeping for
20ms and then the assert.
20ms is a relatively long time, but it also seems reasonable that the
background thread wouldn't be scheduled during that 20ms to get
done_flag set before the ASSERT_TRUE. Instead, wait for reset_flag to be
set to make sure it does get set before the test continues.
Bug: 734130
Change-Id: I8cfb6dc79352079ac95cc2a554327500b8de4ebd
Reviewed-on: https://chromium-review.googlesource.com/538091
Reviewed-by: Gabriel Charette <gab@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#480440}
diff --git a/base/synchronization/atomic_flag_unittest.cc b/base/synchronization/atomic_flag_unittest.cc
index 76e5d968..a7c4d9c 100644
--- a/base/synchronization/atomic_flag_unittest.cc
+++ b/base/synchronization/atomic_flag_unittest.cc
@@ -89,7 +89,8 @@
// Use |reset_flag| to confirm that the above completed (which the rest of
// this test assumes).
- ASSERT_TRUE(reset_flag.IsSet());
+ while (!reset_flag.IsSet())
+ PlatformThread::YieldCurrentThread();
tested_flag.UnsafeResetForTesting();
EXPECT_FALSE(tested_flag.IsSet());