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
/// makeProgress until this Future is ready.
template <class F> 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 {
#include <folly/wangle/InlineExecutor.h>
#include <folly/wangle/ManualExecutor.h>
#include <folly/wangle/QueuedImmediateExecutor.h>
+#include <folly/wangle/Future.h>
+#include <folly/Baton.h>
using namespace folly::wangle;
using namespace std::chrono;
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) {
InlineExecutor x;
size_t counter = 0;