Merge pull request #8094 from abhinavarora/fix_buff_channel_close

Buffered channel should notify both condition variables on close
emailweixu-patch-1
chengduo 7 years ago committed by GitHub
commit 25d5686169
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -49,6 +49,7 @@ class Buffered : public paddle::framework::Channel<T> {
}
void NotifyAllSenders(std::unique_lock<std::mutex>*);
void NotifyAllParticipants(std::unique_lock<std::mutex>*);
};
template <typename T>
@ -80,7 +81,7 @@ template <typename T>
void Buffered<T>::Close() {
std::unique_lock<std::mutex> lock(mu_);
closed_ = true;
NotifyAllSenders(&lock);
NotifyAllParticipants(&lock);
}
template <typename T>
@ -88,7 +89,7 @@ Buffered<T>::~Buffered() {
std::unique_lock<std::mutex> lock(mu_);
closed_ = true;
channel_.clear();
NotifyAllSenders(&lock);
NotifyAllParticipants(&lock);
}
template <typename T>
@ -97,6 +98,13 @@ void Buffered<T>::NotifyAllSenders(std::unique_lock<std::mutex>* lock) {
full_cond_var_.notify_all();
}
template <typename T>
void Buffered<T>::NotifyAllParticipants(std::unique_lock<std::mutex>* lock) {
lock->unlock();
full_cond_var_.notify_all();
empty_cond_var_.notify_all();
}
} // namespace details
} // namespace framework
} // namespace paddle

Loading…
Cancel
Save