From a87ce91c4b93561a913a47350043ef6048f29912 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Mon, 19 Mar 2018 18:30:15 +0800 Subject: [PATCH] Use mtx --- paddle/fluid/framework/parallel_executor.cc | 7 +++---- paddle/fluid/framework/parallel_executor.h | 23 ++++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/framework/parallel_executor.cc b/paddle/fluid/framework/parallel_executor.cc index 450df244b7..773e5c0074 100644 --- a/paddle/fluid/framework/parallel_executor.cc +++ b/paddle/fluid/framework/parallel_executor.cc @@ -641,7 +641,7 @@ void ParallelExecutor::Run(const std::vector &fetch_tensors, auto fetched_data = std::make_shared(fetch_tensors.size()); // Version --> VarHandle member_->exception_.reset(); - std::unordered_map pending_vars; + std::unordered_map pending_vars; std::unordered_map pending_ops; for (auto &place_pair : member_->vars_) { @@ -739,10 +739,9 @@ void ParallelExecutor::Run(const std::vector &fetch_tensors, } void ParallelExecutor::RunOp( - std::unordered_map &pending_vars, + std::unordered_map &pending_vars, OpHandle *op) const { - std::vector *ready_buffer = - new std::vector(); + std::vector *ready_buffer = new std::vector(); for (auto *var : op->outputs_) { ready_buffer->emplace_back(&pending_vars[var]); } diff --git a/paddle/fluid/framework/parallel_executor.h b/paddle/fluid/framework/parallel_executor.h index 150b429f94..b6fa6fb2d8 100644 --- a/paddle/fluid/framework/parallel_executor.h +++ b/paddle/fluid/framework/parallel_executor.h @@ -32,6 +32,27 @@ class ParallelExecutorPrivate; class VarHandle; class OpHandle; class VarHandleBase; + +struct GuardedBool { + public: + GuardedBool() {} + + operator bool() const { + std::lock_guard g(mtx_); + return value_; + } + + GuardedBool& operator=(bool o) { + std::lock_guard g(mtx_); + value_ = o; + return *this; + } + + private: + mutable std::mutex mtx_; + bool value_; +}; + class ParallelExecutor { public: explicit ParallelExecutor(const std::vector& places, @@ -60,7 +81,7 @@ class ParallelExecutor { void BuildNCCLCommunicator() const; - void RunOp(std::unordered_map& pending_vars, + void RunOp(std::unordered_map& pending_vars, OpHandle* op) const; void PolishGraphToSupportDataHarzaeds() const; -- GitLab