Fix race in sync point.

Summary:
The LoadDependency function does not take a lock when it runs
and it could be modifying data structures while other threads are
accessing it.

Test Plan: Run TSAN.

Reviewers: igor, sdong

Reviewed By: igor, sdong

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D34095
This commit is contained in:
Venkatesh Radhakrishnan 2015-02-26 15:11:50 -08:00
parent 03b432d4b8
commit 8984e5f848

View File

@ -14,6 +14,7 @@ SyncPoint* SyncPoint::GetInstance() {
} }
void SyncPoint::LoadDependency(const std::vector<Dependency>& dependencies) { void SyncPoint::LoadDependency(const std::vector<Dependency>& dependencies) {
std::unique_lock<std::mutex> lock(mutex_);
successors_.clear(); successors_.clear();
predecessors_.clear(); predecessors_.clear();
cleared_points_.clear(); cleared_points_.clear();
@ -21,6 +22,7 @@ void SyncPoint::LoadDependency(const std::vector<Dependency>& dependencies) {
successors_[dependency.predecessor].push_back(dependency.successor); successors_[dependency.predecessor].push_back(dependency.successor);
predecessors_[dependency.successor].push_back(dependency.predecessor); predecessors_[dependency.successor].push_back(dependency.predecessor);
} }
cv_.notify_all();
} }
bool SyncPoint::PredecessorsAllCleared(const std::string& point) { bool SyncPoint::PredecessorsAllCleared(const std::string& point) {