Boost C++ Libraries: Ticket #8068: Bad Memory Access in boost::future<>.then() after accessing given future https://svn.boost.org/trac10/ticket/8068 <p> When using "then" on a future and accessing the value of the future in the continuation, the memory of the future is freed/released and the further execution of the continuation happens in an undefined limbo state (leading to a crash with EXC_BAC_ACCESS at least on iOS. </p> <p> Here is a minimal example: </p> <pre class="wiki">#define BOOST_THREAD_VERSION 4 #include &lt;boost/thread.hpp&gt; class Test { public: void test() { boost::shared_ptr&lt;Test&gt; listener(new Test()); boost::future&lt;bool&gt; con = boost::make_future(true); listener-&gt;foo(); // Works boost::future&lt;bool&gt; initDone = con.then([listener](boost::future&lt;bool&gt;&amp; connected) { listener-&gt;foo(); // Works if (!connected.get()) { listener-&gt;foo(); return false; } listener-&gt;foo(); // EXC_BAD_ACCESS return true; }); } void foo() { std::cout &lt;&lt; "foo"; } }; </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8068 Trac 1.4.3 Stephan Mehlhase <s.mehlhase@…> Fri, 15 Feb 2013 07:27:29 GMT attachment set https://svn.boost.org/trac10/ticket/8068 https://svn.boost.org/trac10/ticket/8068 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">after-get.png</span> </li> </ul> <p> Debugger View after get() has been called in continuation </p> Ticket Stephan Mehlhase <s.mehlhase@…> Sun, 17 Feb 2013 08:10:25 GMT component changed https://svn.boost.org/trac10/ticket/8068#comment:1 https://svn.boost.org/trac10/ticket/8068#comment:1 <ul> <li><strong>component</strong> <span class="trac-field-old">threads</span> → <span class="trac-field-new">thread</span> </li> </ul> Ticket viboes Sun, 17 Feb 2013 10:30:13 GMT owner, status changed https://svn.boost.org/trac10/ticket/8068#comment:2 https://svn.boost.org/trac10/ticket/8068#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> <p> I'm aware of the bug. future&lt;&gt;.then is not stable yet. this is why I have not delivered it yet, that is is not in the documentation. Sorry for this. </p> Ticket viboes Sun, 17 Feb 2013 16:44:31 GMT <link>https://svn.boost.org/trac10/ticket/8068#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8068#comment:3</guid> <description> <p> You could try with </p> <pre class="wiki">#define BOOST_THREAD_DONT_PROVIDE_FUTURE_INVALID_AFTER_GET </pre><p> but even with this future&lt;&gt;.then is not stable yet. </p> </description> <category>Ticket</category> </item> <item> <author>Stephan Mehlhase <s.mehlhase@…></author> <pubDate>Mon, 18 Feb 2013 08:04:32 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/8068#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8068#comment:4</guid> <description> <p> Thanks, with disabling the invalidation it seems to work. However, since it is not considered stable yet, I'll switch to using a separate thread in which I'll wait for the future and execute the needed actions afterwards. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 18 Feb 2013 12:14:52 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8068#comment:5 https://svn.boost.org/trac10/ticket/8068#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">invalid</span> </li> </ul> <p> I close the ticket as invalid as the feature is not delivered yet, but I have in mind that this doesn't works yet. </p> Ticket