Skip to content

Commit

Permalink
Fix race condition in AtomicFlagTest.SetOnDifferentSequenceDeathTest
Browse files Browse the repository at this point in the history
There was a race between destructing 'flag' and running ExpectSetFlagDeath
(which refers to 'flag') on the other thread.

BUG=761859

Change-Id: I08e763876f14176b89e741c5f09a25cb10266a73
Reviewed-on: https://chromium-review.googlesource.com/665297
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Hans Wennborg <hans@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501723}
  • Loading branch information
zmodem authored and Commit Bot committed Sep 13, 2017
1 parent d794261 commit d9c39e6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion base/synchronization/atomic_flag_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,17 @@ TEST(AtomicFlagTest, SetOnDifferentSequenceDeathTest) {
// Checks that Set() can't be called from another sequence after being called
// on this one. AtomicFlag should die on a DCHECK if Set() is called again
// from another sequence.

// Note: flag must be declared before the Thread so that its destructor runs
// later. Otherwise there's a race between destructing flag and running
// ExpectSetFlagDeath.
AtomicFlag flag;

::testing::FLAGS_gtest_death_test_style = "threadsafe";
Thread t("AtomicFlagTest.SetOnDifferentThreadDeathTest");
ASSERT_TRUE(t.Start());
EXPECT_TRUE(t.WaitUntilThreadStarted());

AtomicFlag flag;
flag.Set();
t.task_runner()->PostTask(FROM_HERE, BindOnce(&ExpectSetFlagDeath, &flag));
}
Expand Down

0 comments on commit d9c39e6

Please sign in to comment.