From: Andrii Grynenko Date: Wed, 18 May 2016 00:21:56 +0000 (-0700) Subject: Fix one more race in Promise::setTry X-Git-Tag: 2016.07.26~225 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4ffd39d6962255cf227b7dbda2f76a54759069ac;p=folly.git Fix one more race in Promise::setTry Summary: Baton::post has to be the last step of Promise::setTry. If Promise is not owned by the posting thread, it may be destroyed right after Baton::post is called. Reviewed By: pavlo-fb Differential Revision: D3312506 fbshipit-source-id: 6d5c3f0925c3bb9cd3f981e7550f888d5ed76189 --- diff --git a/folly/experimental/fibers/Promise-inl.h b/folly/experimental/fibers/Promise-inl.h index 108a2ac4..67459855 100644 --- a/folly/experimental/fibers/Promise-inl.h +++ b/folly/experimental/fibers/Promise-inl.h @@ -63,9 +63,9 @@ void Promise::setTry(folly::Try&& t) { *value_ = std::move(t); value_ = nullptr; + // Baton::post has to be the last step here, since if Promise is not owned by + // the posting thread, it may be destroyed right after Baton::post is called. baton_->post(); - - baton_ = nullptr; } template