From f326b0117e456e3a0cc6b38bcb819b3b56bef959 Mon Sep 17 00:00:00 2001 From: tensor-tang Date: Thu, 7 Jun 2018 10:56:35 +0800 Subject: [PATCH] refine scope lock --- paddle/fluid/framework/scope.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/paddle/fluid/framework/scope.cc b/paddle/fluid/framework/scope.cc index bb2d866c82..fd23fdeab7 100644 --- a/paddle/fluid/framework/scope.cc +++ b/paddle/fluid/framework/scope.cc @@ -78,6 +78,7 @@ Variable* Scope::FindVarInternal(const std::string& name) const { } const Scope* Scope::FindScope(const Variable* var) const { + std::unique_lock lock(mutex_); for (auto& kv : vars_) { if (kv.second.get() == var) { return this; @@ -127,6 +128,7 @@ void Scope::EraseVars(const std::vector& var_names) { void Scope::Rename(const std::string& origin_name, const std::string& new_name) const { + std::unique_lock lock(mutex_); auto origin_it = vars_.find(origin_name); PADDLE_ENFORCE(origin_it != vars_.end(), "Cannot find original variable with name %s", origin_name); -- GitLab