From 5aa44fb2070479b5bfd88d1e3534439f4d54e238 Mon Sep 17 00:00:00 2001 From: Hans Fugal Date: Tue, 21 Oct 2014 11:55:52 -0700 Subject: [PATCH] waitFor race workaround Summary: Fixing the race will take some more thought. Probably a condvar. For now, I'm turning waitFor into a spinlock instead. Test Plan: new unit test that deadlocks before the workaround Reviewed By: jsedgwick@fb.com Subscribers: trunkagent, net-systems@, fugalh, exa, njormrod, folly-diffs@ FB internal diff: D1628015 Tasks: 5427828 --- folly/wangle/ManualExecutor.h | 8 ++++++++ folly/wangle/test/ExecutorTest.cpp | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/folly/wangle/ManualExecutor.h b/folly/wangle/ManualExecutor.h index 27caf28c..329f9fc6 100644 --- a/folly/wangle/ManualExecutor.h +++ b/folly/wangle/ManualExecutor.h @@ -56,8 +56,16 @@ namespace folly { namespace wangle { /// makeProgress until this Future is ready. template void waitFor(F const& f) { + // TODO(5427828) +#if 0 while (!f.isReady()) makeProgress(); +#else + while (!f.isReady()) { + run(); + } +#endif + } virtual void scheduleAt(Func&& f, TimePoint const& t) override { diff --git a/folly/wangle/test/ExecutorTest.cpp b/folly/wangle/test/ExecutorTest.cpp index 1e60ab0b..b4ec7684 100644 --- a/folly/wangle/test/ExecutorTest.cpp +++ b/folly/wangle/test/ExecutorTest.cpp @@ -18,6 +18,8 @@ #include #include #include +#include +#include using namespace folly::wangle; using namespace std::chrono; @@ -89,6 +91,22 @@ TEST(ManualExecutor, advanceNeg) { EXPECT_EQ(count, 0); } +TEST(ManualExecutor, waitForDoesNotDeadlock) { + ManualExecutor east, west; + folly::Baton<> baton; + auto f = makeFuture() + .via(&east) + .then([](Try){ return makeFuture(); }) + .via(&west); + std::thread t([&]{ + baton.post(); + west.waitFor(f); + }); + baton.wait(); + east.run(); + t.join(); +} + TEST(Executor, InlineExecutor) { InlineExecutor x; size_t counter = 0; -- 2.34.1