Fix SharedPromise::isFulfilled doesn't get back correct value when it's running in...
authorBi Xue <bixue@fb.com>
Mon, 26 Jun 2017 19:19:40 +0000 (12:19 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 26 Jun 2017 19:24:35 +0000 (12:24 -0700)
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

folly/futures/SharedPromise-inl.h

index 185062acdbcc01afbc5fd19ee543dadcc06a4b06..9def3bc68658820600853a9380f604b9000a8cf1 100644 (file)
@@ -131,6 +131,7 @@ void SharedPromise<T>::setTry(Try<T>&& t) {
 
 template <class T>
 bool SharedPromise<T>::isFulfilled() {
+  std::lock_guard<std::mutex> g(mutex_);
   return hasValue_;
 }