Commit 5aa44fb2 authored by Hans Fugal's avatar Hans Fugal Committed by dcsommer

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
parent 4459989b
...@@ -56,8 +56,16 @@ namespace folly { namespace wangle { ...@@ -56,8 +56,16 @@ namespace folly { namespace wangle {
/// makeProgress until this Future is ready. /// makeProgress until this Future is ready.
template <class F> void waitFor(F const& f) { template <class F> void waitFor(F const& f) {
// TODO(5427828)
#if 0
while (!f.isReady()) while (!f.isReady())
makeProgress(); makeProgress();
#else
while (!f.isReady()) {
run();
}
#endif
} }
virtual void scheduleAt(Func&& f, TimePoint const& t) override { virtual void scheduleAt(Func&& f, TimePoint const& t) override {
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include <folly/wangle/InlineExecutor.h> #include <folly/wangle/InlineExecutor.h>
#include <folly/wangle/ManualExecutor.h> #include <folly/wangle/ManualExecutor.h>
#include <folly/wangle/QueuedImmediateExecutor.h> #include <folly/wangle/QueuedImmediateExecutor.h>
#include <folly/wangle/Future.h>
#include <folly/Baton.h>
using namespace folly::wangle; using namespace folly::wangle;
using namespace std::chrono; using namespace std::chrono;
...@@ -89,6 +91,22 @@ TEST(ManualExecutor, advanceNeg) { ...@@ -89,6 +91,22 @@ TEST(ManualExecutor, advanceNeg) {
EXPECT_EQ(count, 0); EXPECT_EQ(count, 0);
} }
TEST(ManualExecutor, waitForDoesNotDeadlock) {
ManualExecutor east, west;
folly::Baton<> baton;
auto f = makeFuture()
.via(&east)
.then([](Try<void>){ return makeFuture(); })
.via(&west);
std::thread t([&]{
baton.post();
west.waitFor(f);
});
baton.wait();
east.run();
t.join();
}
TEST(Executor, InlineExecutor) { TEST(Executor, InlineExecutor) {
InlineExecutor x; InlineExecutor x;
size_t counter = 0; size_t counter = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment