Skip to content

Commit f326b01

Browse files
committed
refine scope lock
1 parent 9cf1f35 commit f326b01

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

paddle/fluid/framework/scope.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Variable* Scope::FindVarInternal(const std::string& name) const {
7878
}
7979

8080
const Scope* Scope::FindScope(const Variable* var) const {
81+
std::unique_lock<std::mutex> lock(mutex_);
8182
for (auto& kv : vars_) {
8283
if (kv.second.get() == var) {
8384
return this;
@@ -127,6 +128,7 @@ void Scope::EraseVars(const std::vector<std::string>& var_names) {
127128

128129
void Scope::Rename(const std::string& origin_name,
129130
const std::string& new_name) const {
131+
std::unique_lock<std::mutex> lock(mutex_);
130132
auto origin_it = vars_.find(origin_name);
131133
PADDLE_ENFORCE(origin_it != vars_.end(),
132134
"Cannot find original variable with name %s", origin_name);

0 commit comments

Comments
 (0)