Re: [Boost-bugs] [Boost C++ Libraries] #3848: Boost.Exception and transporting exceptions between threads

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #3848: Boost.Exception and transporting exceptions between threads
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-01-20 12:15:28


#3848: Boost.Exception and transporting exceptions between threads
--------------------------------------------------+-------------------------
  Reporter: Nikki Chumakov <nikkikom@…> | Owner: emildotchevski
      Type: Bugs | Status: reopened
 Milestone: | Component: exception
   Version: Boost 1.40.0 | Severity: Problem
Resolution: | Keywords: exception thread safety
--------------------------------------------------+-------------------------
Changes (by Nikki Chumakov <nikkikom@…>):

  * status: closed => reopened
  * resolution: invalid =>

Comment:

 Please take a look at example a little bit closer.

 I'm not transferring boost::exception object between threads, I'm
 transferring exception_ptr.

 Boost.Exception docs says about thread safety:

 * It is legal for multiple threads to hold exception_ptr references to the
 same exception object.
 * It is illegal for multiple threads to modify the same exception_ptr
 object concurrently.
 * While calling current_exception makes a copy of the current exception
 object, it is still possible for the two copies to share internal state.
 Therefore, in general it is not safe to call rethrow_exception
 concurrently to throw the same exception object into multiple threads.

 Well, I do not modify same exception_ptr object concurrently.
 And I do not call rethrow_exception concurrently to throw the same
 exception object.

 I guess the race condition happen when temporal boost::exception object
 destructor called in producer thread in the very same time when
 rethrow_exception called in consumer thread.

 I applied the changes you suggested, the example still crashes. Please
 take a look at attached exc1.cc and exc1_log.txt.

 BTW, it is possible to reproduce the very same bug with
 boost::promise/boost::future in 1.41+

 {{{
 void producer (boost::promise<void>& promise, boost::barrier& barrier)
 {
   barrier.wait ();
   promise.set_exception (boost::copy_exception (err () << err_info
 ("stub")));
 }

 void consumer ()
 {
   boost::barrier barrier (2);
   boost::promise<void> promise;
   boost::unique_future<void> future = promise.get_future ();

   boost::thread thr (
       boost::bind (&producer,
                     boost::ref (promise),
                     boost::ref (barrier))
   );

   barrier.wait ();

   try { future.get (); }
   catch (err const& e) {}

   thr.join ();
 }
 }}}

 It should fail as well.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3848#comment:3>
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:02 UTC