Boost C++ Libraries: Ticket #11220: future<>::wait_for() on continuation doesn't return after timeout. https://svn.boost.org/trac10/ticket/11220 <p> If the original future's value will never be set, the wait_for() on continuation will deadlock. </p> <p> I'm using Boost 1.58 with Thread patched to commit 0bed674233a3c94b7254037dc4903961b54eb141 . </p> <p> Example to reproduce: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#define BOOST_THREAD_VERSION 4</span> <span class="cp">#define BOOST_THREAD_PROVIDES_EXECUTORS</span> <span class="cp">#include</span> <span class="cpf">&lt;boost/thread.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/thread/executor.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/thread/thread_pool.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;future&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;chrono&gt;</span><span class="cp"></span> <span class="kt">void</span> <span class="nf">wait_for</span><span class="p">()</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="n">promise</span><span class="o">&lt;</span><span class="kt">void</span><span class="o">&gt;</span> <span class="n">promise</span><span class="p">;</span> <span class="k">auto</span> <span class="n">future</span> <span class="o">=</span> <span class="n">promise</span><span class="p">.</span><span class="n">get_future</span><span class="p">();</span> <span class="n">future</span><span class="p">.</span><span class="n">wait_for</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">chrono</span><span class="o">::</span><span class="n">milliseconds</span><span class="p">(</span><span class="mi">100</span><span class="p">));</span> <span class="p">}</span> <span class="kt">void</span> <span class="nf">wait_for_executor</span><span class="p">()</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="n">promise</span><span class="o">&lt;</span><span class="kt">void</span><span class="o">&gt;</span> <span class="n">promise</span><span class="p">;</span> <span class="k">auto</span> <span class="n">future</span> <span class="o">=</span> <span class="n">promise</span><span class="p">.</span><span class="n">get_future</span><span class="p">();</span> <span class="k">auto</span> <span class="n">far_future</span> <span class="o">=</span> <span class="n">future</span><span class="p">.</span><span class="n">then</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">launch</span><span class="o">::</span><span class="n">async</span><span class="p">,</span> <span class="p">[](</span><span class="k">auto</span><span class="p">){});</span> <span class="n">far_future</span><span class="p">.</span><span class="n">wait_for</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">chrono</span><span class="o">::</span><span class="n">milliseconds</span><span class="p">(</span><span class="mi">100</span><span class="p">));</span> <span class="p">}</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="c1">// works</span> <span class="n">wait_for</span><span class="p">();</span> <span class="c1">// deadlocks</span> <span class="n">wait_for_executor</span><span class="p">();</span> <span class="p">}</span> </pre></div></div><p> GDB backtrace: </p> <pre class="wiki">Thread 1 (Thread 0x7ffff7fe6780 (LWP 247)): #0 pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185 #1 0x000000000040df1e in boost::condition_variable::wait (this=0x63f3e8, m=...) at /usr/include/boost/thread/pthread/condition_variable.hpp:73 #2 0x00000000004105a1 in boost::detail::shared_state_base::wait_internal (this=0x63f380, lk=..., rethrow=false) at /usr/include/boost/thread/future.hpp:305 #3 0x000000000041061a in boost::detail::shared_state_base::wait (this=0x63f380, lock=..., rethrow=false) at /usr/include/boost/thread/future.hpp:315 #4 0x0000000000422c1f in boost::detail::future_async_shared_state_base&lt;void&gt;::wait ( this=0x63f380, lk=..., rethrow=false) at /usr/include/boost/thread/future.hpp:771 #5 0x0000000000422bb6 in boost::detail::future_async_shared_state_base&lt;void&gt;::block_if_needed (this=0x63f380, lk=...) at /usr/include/boost/thread/future.hpp:757 #6 0x000000000040fed6 in boost::detail::shared_state_base::dec (this=0x63f380, lk=...) at /usr/include/boost/thread/future.hpp:181 #7 0x000000000040ff1e in boost::detail::shared_state_base::dec (this=0x63f380) at /usr/include/boost/thread/future.hpp:184 #8 0x000000000041a2b6 in boost::detail::basic_future&lt;void&gt;::~basic_future ( this=0x7fffffffeb80, __in_chrg=&lt;optimized out&gt;) at /usr/include/boost/thread/future.hpp:1188 #9 0x00000000004147ca in boost::future&lt;void&gt;::~future (this=0x7fffffffeb80, __in_chrg=&lt;optimized out&gt;) at /usr/include/boost/thread/future.hpp:1541 #10 0x000000000040a920 in wait_for_executor () at wait_for_example.cpp:20 #11 0x000000000040a99f in main () at wait_for_example.cpp:29 </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11220 Trac 1.4.3 Konrad Zemek <konrad.zemek@…> Wed, 22 Apr 2015 09:40:47 GMT <link>https://svn.boost.org/trac10/ticket/11220#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11220#comment:1</guid> <description> <p> I've just noticed - it's not <code>wait_for</code> that locks, it's the <code>far_future</code>'s destructor that locks here, which is consistent with the documentation: </p> <blockquote class="citation"> <p> The returned futures behave as the ones returned from boost::async, the destructor of the future object returned from then will block. </p> </blockquote> <p> I will have to find a workaround, but it's not a bug. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 24 Apr 2015 21:48:16 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/11220#comment:2 https://svn.boost.org/trac10/ticket/11220#comment:2 <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 Fri, 24 Apr 2015 21:49:20 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11220#comment:3 https://svn.boost.org/trac10/ticket/11220#comment:3 <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">invalid</span> </li> </ul> Ticket