[Boost-bugs] [Boost C++ Libraries] #8596: With C++0x enabled, boost::packaged_task stores a reference to function objects, instead of a copy

Subject: [Boost-bugs] [Boost C++ Libraries] #8596: With C++0x enabled, boost::packaged_task stores a reference to function objects, instead of a copy
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-05-20 11:59:14


#8596: With C++0x enabled, boost::packaged_task stores a reference to function
objects, instead of a copy
----------------------------------------------------------+-----------------
 Reporter: Kees-Jan Dijkzeul <kees-jan.dijkzeul@…> | Owner: anthonyw
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
  Version: Boost 1.53.0 | Severity: Problem
 Keywords: |
----------------------------------------------------------+-----------------
 I have build a Treadpool using boost::thread. In porting it to boost 1.53,
 I've found a regression.

 Consider attached test-program. It runs correctly on boost 1.49 and
 earlier. It runs correctly on boost 1.53, with C++0x disabled. With C++0x
 enabled, it crashes due to an uncaught exception "call to empty
 boost::function"

 Failure has been observed on Ubuntu Saucy, I.e. boost 1.53, gcc 4.8.0,
 linux kernel 3.9.0.

 After some debugging, I believe the problem is caused by packaged_task
 storing a reference to the boost::function object, instead of a copy. As
 the boost::function object is a temporary, this leads to undefined
 behavior further on.

 I'm guessing this problem is introduced in [81117] By below patch to
 boost/thread/future.hpp
 {{{
  #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
          template <class F>
          explicit packaged_task(BOOST_THREAD_RV_REF(F) f
              , typename disable_if<is_same<typename decay<F>::type,
 packaged_task>, \
 dummy* >::type=0 )
          {
 - typedef typename remove_cv<typename
 remove_reference<F>::type>::type FR;
 + //typedef typename remove_cv<typename
 remove_reference<F>::type>::type FR;
 + typedef F FR;
  #if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK
 ....
 }}}

 Attached: Small application showing the problem

 For original code please visit https://github.com/kees-
 jan/scroom/blob/master/inc/scroom/impl/threadpoolimpl.hh#L90

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8596>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:13 UTC