From: Bi Xue Date: Mon, 26 Jun 2017 19:19:40 +0000 (-0700) Subject: Fix SharedPromise::isFulfilled doesn't get back correct value when it's running in... X-Git-Tag: v2017.07.03.00~33 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6cf4cd30fc40660978b14c118db081da529b7a88;p=folly.git 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 --- diff --git a/folly/futures/SharedPromise-inl.h b/folly/futures/SharedPromise-inl.h index 185062ac..9def3bc6 100644 --- a/folly/futures/SharedPromise-inl.h +++ b/folly/futures/SharedPromise-inl.h @@ -131,6 +131,7 @@ void SharedPromise::setTry(Try&& t) { template bool SharedPromise::isFulfilled() { + std::lock_guard g(mutex_); return hasValue_; }