Boost C++ Libraries: Ticket #4521: Error using boost::move on packaged_task (MSVC 10) https://svn.boost.org/trac10/ticket/4521 <p> Hi, </p> <p> the example code on futures is broken on MSVC 10 <a href="http://www.boost.org/doc/libs/1_43_0/doc/html/thread/synchronization.html#thread.synchronization.futures">http://www.boost.org/doc/libs/1_43_0/doc/html/thread/synchronization.html#thread.synchronization.futures</a> </p> <pre class="wiki">int calculate_the_answer_to_life_the_universe_and_everything() { return 42; } boost::packaged_task&lt;int&gt; pt(calculate_the_answer_to_life_the_universe_and_everything); boost::unique_future&lt;int&gt; fi=pt.get_future(); boost::thread task(boost::move(pt)); // launch task on a thread </pre><p> However it works if BOOST_NO_RVALUE_REFERENCES is defined. Reproducible on v1.43 and 1.44 beta1 </p> <p> Error: </p> <pre class="wiki">1&gt;shared\check_exist.cpp(16): error C2665: 'boost::move' : none of the 2 overloads could convert all the argument types 1&gt; C:\Program Files\C++\Boost\boost/thread/detail/thread.hpp(359): could be 'boost::thread &amp;&amp;boost::move(boost::thread &amp;)' 1&gt; C:\Program Files\C++\Boost\boost/thread/detail/thread.hpp(363): or 'boost::thread &amp;&amp;boost::move(boost::thread &amp;&amp;)' </pre><p> Regards, <a class="missing wiki">ZenJu</a> </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4521 Trac 1.4.3 Marshall Clow Mon, 15 Nov 2010 22:20:43 GMT component, milestone changed; owner set https://svn.boost.org/trac10/ticket/4521#comment:1 https://svn.boost.org/trac10/ticket/4521#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Anthony Williams</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">thread</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.44.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket viboes Wed, 17 Nov 2010 20:12:40 GMT summary changed; cc set https://svn.boost.org/trac10/ticket/4521#comment:2 https://svn.boost.org/trac10/ticket/4521#comment:2 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> added </li> <li><strong>summary</strong> <span class="trac-field-old">Error using boost::move on packaged_task</span> → <span class="trac-field-new">Error using boost::move on packaged_task (MSVC 10)</span> </li> </ul> Ticket Claudio Bley Wed, 02 Nov 2011 11:34:17 GMT <link>https://svn.boost.org/trac10/ticket/4521#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4521#comment:3</guid> <description> <p> This example also fails with GCC 4.5.4 and 4.6.1 using -std=c++0x: </p> <pre class="wiki">g++ -std=c++0x answer.cc -I /home/claudio/aux/include/boost-1_47/ In file included from /home/claudio/aux/include/boost-1_47/boost/thread/thread.hpp:22:0, from /home/claudio/aux/include/boost-1_47/boost/thread.hpp:13, from answer.cc:1: /home/claudio/aux/include/boost-1_47/boost/thread/future.hpp: In constructor ‘boost::detail::thread_data&lt;F&gt;::thread_data(F&amp;) [with F = boost::packaged_task&lt;int&gt;]’: /home/claudio/aux/include/boost-1_47/boost/thread/pthread/thread_heap_alloc.hpp:24:47: instantiated from ‘T* boost::detail::heap_new(A1&amp;&amp;) [with T = boost::detail::thread_data&lt;boost::packaged_task&lt;int&gt; &gt;, A1 = boost::packaged_task&lt;int&gt;&amp;]’ /home/claudio/aux/include/boost-1_47/boost/thread/detail/thread.hpp:130:146: instantiated from ‘static boost::detail::thread_data_ptr boost::thread::make_thread_info(F&amp;&amp;) [with F = boost::packaged_task&lt;int&gt;&amp;, boost::detail::thread_data_ptr = boost::shared_ptr&lt;boost::detail::thread_data_base&gt;]’ /home/claudio/aux/include/boost-1_47/boost/thread/detail/thread.hpp:168:62: instantiated from ‘boost::thread::thread(F&amp;&amp;) [with F = boost::packaged_task&lt;int&gt;&amp;]’ answer.cc:17:36: instantiated from here /home/claudio/aux/include/boost-1_47/boost/thread/future.hpp:1268:9: error: ‘boost::packaged_task&lt;R&gt;::packaged_task(boost::packaged_task&lt;R&gt;&amp;) [with R = int, boost::packaged_task&lt;R&gt; = boost::packaged_task&lt;int&gt;]’ is private /home/claudio/aux/include/boost-1_47/boost/thread/detail/thread.hpp:49:21: error: within this context </pre><p> There are only 2 overloads of boost::move, and these don't work for a packaged_task. </p> <p> boost::move should be equivalent to std::move ifndef BOOST_NO_RVALUE_REFERENCES, shouldn't it? </p> <p> Simply </p> <div class="wiki-code"><div class="code"><pre><span class="k">namespace</span> <span class="n">boost</span> <span class="p">{</span> <span class="k">using</span> <span class="n">std</span><span class="o">::</span><span class="n">move</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> works with MSVC 10 and GCC 4.5, 4.6. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sun, 11 Dec 2011 11:39:48 GMT</pubDate> <title>keywords set https://svn.boost.org/trac10/ticket/4521#comment:4 https://svn.boost.org/trac10/ticket/4521#comment:4 <ul> <li><strong>keywords</strong> move added </li> </ul> <p> There is an action point to use Boost.Move. Could we consider this as a duplicate of <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6194" title="#6194: Feature Requests: Adapt to Boost.Move (closed: fixed)">#6194</a> Adapt to Boost.Move. </p> Ticket viboes Wed, 14 Dec 2011 22:48:29 GMT <link>https://svn.boost.org/trac10/ticket/4521#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4521#comment:5</guid> <description> <p> If we follows the reference documentation, the example should not works as the functor (in this case a packaged task) must be copyable. </p> <pre class="wiki">Thread Constructor template&lt;typename Callable&gt; thread(Callable func); Preconditions: Callable must by copyable. Effects: func is copied into storage managed internally by the thread library, and that copy is invoked on a newly-created thread of execution. If this invocation results in an exception being propagated into the internals of the thread library that is not of type boost::thread_interrupted, then std::terminate() will be called. Postconditions: *this refers to the newly created thread of execution. Throws: boost::thread_resource_error if an error occurs. Thread Constructor with arguments template &lt;class F,class A1,class A2,...&gt; thread(F f,A1 a1,A2 a2,...); Preconditions: F and each An must by copyable or movable. Effects: As if thread(boost::bind(f,a1,a2,...)). Consequently, f and each an are copied into internal storage for access by the new thread. Postconditions: *this refers to the newly created thread of execution. Throws: boost::thread_resource_error if an error occurs. Note: Currently up to nine additional arguments a1 to a9 can be specified in addition to the function f. </pre><p> This doesn't means that the library shouldn't provide such a feature as otherwise it is unable to work with packaged_task. I have created a feature request for this purpose <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6270" title="#6270: Feature Requests: c++11 compliance: Add thread constructor from movable callable and ... (closed: fixed)">#6270</a> c++11 compliance: Add thread constructor from movable callable and movable arguments. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 31 Dec 2011 17:58:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4521#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4521#comment:6</guid> <description> <p> I have tested on trunk with msvc.10 and it is working. Could you give a try on trunk? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 07 Jan 2012 23:43:46 GMT</pubDate> <title>owner, status changed https://svn.boost.org/trac10/ticket/4521#comment:7 https://svn.boost.org/trac10/ticket/4521#comment:7 <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 Tue, 17 Jan 2012 07:01:19 GMT milestone changed https://svn.boost.org/trac10/ticket/4521#comment:8 https://svn.boost.org/trac10/ticket/4521#comment:8 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.49.0</span> </li> </ul> <p> Committed in trunk at revision <a class="changeset" href="https://svn.boost.org/trac10/changeset/76543" title=" * [@http://svn.boost.org/trac/boost/ticket/2741 #2741] Proposal to ...">[76543]</a>. </p> Ticket viboes Mon, 28 May 2012 16:42:34 GMT status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/4521#comment:9 https://svn.boost.org/trac10/ticket/4521#comment:9 <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> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.49.0</span> → <span class="trac-field-new">Boost 1.50.0</span> </li> </ul> <p> Committed in release branch at <a class="changeset" href="https://svn.boost.org/trac10/changeset/78543" title="Merged boost.thread from trunk">[78543]</a> </p> Ticket