Boost C++ Libraries: Ticket #10964: future<future<T>>::unwrap().then() Deadlocks https://svn.boost.org/trac10/ticket/10964 <p> The shared_state returned by unwrap() doesn't appear to propagate continuation information properly. The following code will deadlock, but the continuations should be immediately invoked. </p> <pre class="wiki">struct TestCallback { typedef boost::future&lt;void&gt; result_type; result_type operator()(boost::future&lt;void&gt; future) const { future.get(); return boost::make_ready_future(); } result_type operator()(boost::future&lt;boost::future&lt;void&gt;&gt; future) const { future.get(); return boost::make_ready_future(); } }; int main() { boost::make_ready_future().then( TestCallback()).unwrap().then(TestCallback()).get(); return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/10964 Trac 1.4.3 viboes Sat, 24 Jan 2015 10:47:31 GMT owner, status changed https://svn.boost.org/trac10/ticket/10964#comment:1 https://svn.boost.org/trac10/ticket/10964#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket viboes Sat, 24 Jan 2015 15:50:34 GMT milestone changed https://svn.boost.org/trac10/ticket/10964#comment:2 https://svn.boost.org/trac10/ticket/10964#comment:2 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.58.0</span> </li> </ul> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/c16ec42941a92210033bddee3ef4eb42fd2b1a03"><span class="icon">​</span>https://github.com/boostorg/thread/commit/c16ec42941a92210033bddee3ef4eb42fd2b1a03</a> </p> Ticket viboes Sat, 31 Jan 2015 10:12:14 GMT <link>https://svn.boost.org/trac10/ticket/10964#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:3</guid> <description> <p> The following doesn't work after the patch </p> <pre class="wiki"> boost::async(f).then( TestCallback()).unwrap().then(TestCallback()).get(); </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 01 Feb 2015 13:57:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10964#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:4</guid> <description> <p> This commit should fix it </p> <p> <a class="ext-link" href="https://github.com/boostorg/thread/commit/45510facc743aa348e501642ce3d607d12dc7cfc"><span class="icon">​</span>https://github.com/boostorg/thread/commit/45510facc743aa348e501642ce3d607d12dc7cfc</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 02 Feb 2015 05:48:22 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10964#comment:5 https://svn.boost.org/trac10/ticket/10964#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Merge to master <a class="ext-link" href="https://github.com/boostorg/thread/commit/71997bd9aa43e1da2f05cdd46219d152a1c2321f"><span class="icon">​</span>https://github.com/boostorg/thread/commit/71997bd9aa43e1da2f05cdd46219d152a1c2321f</a> </p> Ticket viboes Tue, 08 Sep 2015 19:32:13 GMT status, milestone changed; resolution deleted https://svn.boost.org/trac10/ticket/10964#comment:6 https://svn.boost.org/trac10/ticket/10964#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.58.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> The problem is yet there </p> <p> See <a href="http://www.boost.org/development/tests/develop/developer/output/Flast-FreeBSD10-gcc-6-0-0~gnu++11-boost-bin-v2-libs-thread-test-test_10964-test-gcc-6-0-0-debug-threading-multi.html">http://www.boost.org/development/tests/develop/developer/output/Flast-FreeBSD10-gcc-6-0-0~gnu++11-boost-bin-v2-libs-thread-test-test_10964-test-gcc-6-0-0-debug-threading-multi.html</a> </p> <p> and </p> <p> <a href="http://www.boost.org/development/tests/develop/developer/output/Flast-FreeBSD10-gcc-5-1-0~gnu++11-boost-bin-v2-libs-thread-test-ex_future_unwrap-test-gcc-5-1-0-debug-threading-multi.html">http://www.boost.org/development/tests/develop/developer/output/Flast-FreeBSD10-gcc-5-1-0~gnu++11-boost-bin-v2-libs-thread-test-ex_future_unwrap-test-gcc-5-1-0-debug-threading-multi.html</a> </p> <pre class="wiki">terminate called after throwing an instance of 'boost::exception_detail::clone_impl&lt;boost::exception_detail::error_info_injector&lt;boost::lock_error&gt; &gt;' what(): boost: mutex lock failed in pthread_mutex_lock: Resource deadlock avoided </pre> Ticket viboes Tue, 08 Sep 2015 19:41:35 GMT status changed https://svn.boost.org/trac10/ticket/10964#comment:7 https://svn.boost.org/trac10/ticket/10964#comment:7 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">new</span> </li> </ul> Ticket viboes Fri, 25 Sep 2015 05:46:05 GMT status changed https://svn.boost.org/trac10/ticket/10964#comment:8 https://svn.boost.org/trac10/ticket/10964#comment:8 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> Ticket code@… Tue, 06 Oct 2015 01:57:11 GMT <link>https://svn.boost.org/trac10/ticket/10964#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:9</guid> <description> <p> I can look into this if you don't have the time. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 10 Oct 2015 15:07:31 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10964#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:10</guid> <description> <p> Yes, please. Any help will be welcome, an hint, a trace back, requesting for something you don't understand and find weird. </p> <p> It would be great if you test with the branch <a class="ext-link" href="https://github.com/boostorg/thread/tree/feature/make_executors_copyable"><span class="icon">​</span>https://github.com/boostorg/thread/tree/feature/make_executors_copyable</a>, which make use of non-blocking futures also. </p> <p> BTW, what is your name? </p> </description> <category>Ticket</category> </item> <item> <author>code@…</author> <pubDate>Sat, 10 Oct 2015 21:06:21 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10964#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:11</guid> <description> <p> Lee Clagett. I've discussed Futures with you on the mailing list before. Unfortunately my name is after the @ in my email, so it doesn't show here, didn't think about that. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 10 Oct 2015 23:51:46 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10964#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:12</guid> <description> <p> Glad to meet you Lee. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 15 Nov 2015 00:00:44 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10964#comment:13 https://svn.boost.org/trac10/ticket/10964#comment:13 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> It seems that <a class="ext-link" href="https://github.com/boostorg/thread/commit/60a8cb9b5c69423ee0bea403cacc971606575f01"><span class="icon">​</span>https://github.com/boostorg/thread/commit/60a8cb9b5c69423ee0bea403cacc971606575f01</a> fixes it. </p> <p> I don't see anymore the errors. </p> Ticket code@… Sun, 15 Nov 2015 03:06:36 GMT <link>https://svn.boost.org/trac10/ticket/10964#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:14</guid> <description> <p> I noticed that too. Looks like this is going to be a fun one. </p> <p> I tried to recreate this issue on OSX (closest to FreeBSD I had), but no luck. And Clang's tsan isn't supported on OSX, at least on my version. I now have a FreeBSD VM, but I just found out that tsan isn't supported on this platform either! I'll run the tests on this system anyway, before moving to one my Linux systems with tsan. After that its begging Flast to do some investigating for me with some code auditing on the side. </p> </description> <category>Ticket</category> </item> <item> <author>code@…</author> <pubDate>Sun, 15 Nov 2015 03:07:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10964#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:15</guid> <description> <p> Oh, and is it possible that he had a bad build? I feel like that may have happened on one of his systems, I'll try to ask him that ASAP. </p> </description> <category>Ticket</category> </item> <item> <author>Mattéo Delabre ✏ <contact@…></author> <pubDate>Thu, 06 Jul 2017 06:46:05 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10964#comment:16 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:16</guid> <description> <p> I’ve encountered a similar problem while using deferred continuations (see <a class="ext-link" href="https://stackoverflow.com/questions/44748568/boostfuture-deferred-continuation-unwrapping-deadlocks"><span class="icon">​</span>https://stackoverflow.com/questions/44748568/boostfuture-deferred-continuation-unwrapping-deadlocks</a>). </p> <pre class="wiki">#define BOOST_THREAD_VERSION 5 #include &lt;iostream&gt; #include &lt;boost/thread/future.hpp&gt; int main(int argc, char* argv[]) { boost::promise&lt;int&gt; promise; boost::future&lt;int&gt; future = promise.get_future(); promise.set_value(42); int result = future.then( boost::launch::deferred, [](boost::future&lt;int&gt; result) { return boost::make_ready_future(result.get()); } ).unwrap().get(); std::cout &lt;&lt; "Result is: " &lt;&lt; result &lt;&lt; std::endl; return 0; } </pre><p> This code causes a deadlock. If the launch policy is replaced by <code>boost::launch::async</code>, it works as intended. </p> </description> <category>Ticket</category> </item> <item> <author>Mattéo Delabre ✏ <contact@…></author> <pubDate>Thu, 06 Jul 2017 06:46:54 GMT</pubDate> <title>status changed; resolution deleted https://svn.boost.org/trac10/ticket/10964#comment:17 https://svn.boost.org/trac10/ticket/10964#comment:17 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> Ticket Mattéo Delabre ✏ <contact@…> Thu, 06 Jul 2017 06:48:11 GMT cc set https://svn.boost.org/trac10/ticket/10964#comment:18 https://svn.boost.org/trac10/ticket/10964#comment:18 <ul> <li><strong>cc</strong> <span class="trac-author">contact@…</span> added </li> </ul> Ticket viboes Sun, 27 Aug 2017 19:49:00 GMT <link>https://svn.boost.org/trac10/ticket/10964#comment:19 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:19</guid> <description> <p> @Matteo Please, create a new issue, as the case you are describing is different than the original one. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 28 Aug 2017 04:38:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10964#comment:20 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:20</guid> <description> <p> See "VS 2017.4 Preview deadlocks on Test 10964" <a class="ext-link" href="https://github.com/boostorg/thread/issues/132"><span class="icon">​</span>https://github.com/boostorg/thread/issues/132</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 28 Aug 2017 05:01:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/10964#comment:21 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/10964#comment:21</guid> <description> <p> Matteo, could you try with </p> <pre class="wiki">#define BOOST_THREAD_VERSION 4 </pre><p> Version 5 has not been delivered officially. </p> <p> The main difference of version 5 would be that BOOST_THREAD_ASYNC_FUTURE_WAITS is not defined (BOOST_THREAD_FUTURE_BLOCKING neither). </p> <pre class="wiki"> ~future_async_shared_state_base() { #ifdef BOOST_THREAD_FUTURE_BLOCKING join(); #elif defined BOOST_THREAD_ASYNC_FUTURE_WAITS unique_lock&lt;boost::mutex&gt; lk(this-&gt;mutex); while(!this-&gt;done) { this-&gt;waiters.wait(lk); } #endif } </pre><p> but I have no tested it too much. It seems that there are some big implications. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 28 Aug 2017 05:05:56 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/10964#comment:22 https://svn.boost.org/trac10/ticket/10964#comment:22 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket