From 6cf4cd30fc40660978b14c118db081da529b7a88 Mon Sep 17 00:00:00 2001 From: Bi Xue Date: Mon, 26 Jun 2017 12:19:40 -0700 Subject: [PATCH 1/1] 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 --- folly/futures/SharedPromise-inl.h | 1 + 1 file changed, 1 insertion(+) 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_; } -- 2.34.1