Commit d6931011 authored by Robin Cheng's avatar Robin Cheng Committed by Facebook GitHub Bot

Fix a simple race condition FutureDAGTest.

Summary:
In the "Complex" test we can have nodes running at the same time. So
appending to the same vector concurrency isn't safe. Protecting that with a
mutex.

Reviewed By: yfeldblum

Differential Revision: D23545746

fbshipit-source-id: b6f6e8b7204cf63c7e8fbbd8fc5134cb66c8180a
parent 3427f219
...@@ -85,6 +85,7 @@ struct FutureDAGTest : public testing::Test { ...@@ -85,6 +85,7 @@ struct FutureDAGTest : public testing::Test {
struct TestNode { struct TestNode {
explicit TestNode(FutureDAGTest* test) explicit TestNode(FutureDAGTest* test)
: func([this, test] { : func([this, test] {
std::lock_guard<std::mutex> lock(test->orderMutex);
test->order.push_back(handle); test->order.push_back(handle);
return Future<Unit>(); return Future<Unit>();
}), }),
...@@ -98,6 +99,7 @@ struct FutureDAGTest : public testing::Test { ...@@ -98,6 +99,7 @@ struct FutureDAGTest : public testing::Test {
const std::shared_ptr<FutureDAG> dag = const std::shared_ptr<FutureDAG> dag =
FutureDAG::create(getGlobalCPUExecutor()); FutureDAG::create(getGlobalCPUExecutor());
std::map<Handle, std::unique_ptr<TestNode>> nodes; std::map<Handle, std::unique_ptr<TestNode>> nodes;
std::mutex orderMutex;
std::vector<Handle> order; std::vector<Handle> order;
}; };
......
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