Commit 6cf4cd30 authored by Bi Xue's avatar Bi Xue Committed by Facebook Github Bot

Fix SharedPromise::isFulfilled doesn't get back correct value when it's...

Fix SharedPromise::isFulfilled doesn't get back correct value when it's running in a different thread of SharedPromise::setValue

Summary: The implementation of `SharedPromise::isFulfilled` return `hasValue_` directly without taking a lock. `isFulfilled` can be accessed concurrently, but `hasValue_` is not synchronized. Adding a lock fix the issue.

Reviewed By: yfeldblum

Differential Revision: D5319030

fbshipit-source-id: a94b12ed277aa64254680ae84cb18946226cceea
parent c5184205
...@@ -131,6 +131,7 @@ void SharedPromise<T>::setTry(Try<T>&& t) { ...@@ -131,6 +131,7 @@ void SharedPromise<T>::setTry(Try<T>&& t) {
template <class T> template <class T>
bool SharedPromise<T>::isFulfilled() { bool SharedPromise<T>::isFulfilled() {
std::lock_guard<std::mutex> g(mutex_);
return hasValue_; return hasValue_;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment