Call current_exception in parallel for the same exception object

Would turn to the community for clarification is not entirely clear to me situation.

We are talking about exception_ptr, current_exception and rethrow_exception into boost. The problem is the following: should there be protoceratops execution current_exception (in multiple threads) after rethrow_exception for the General exception object.


#include <iostream>
#include <exception>
#include <stdexcept>
#include <vector>

//#define USE_CPP11

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <thread>
#include <future>
#include <memory>
#else
#include <boost>
#include <boost>
using namespace boost;
#endif

using namespace std;

void executer(mutex& mtx, exception_ptr ex)
{
 for(int i = 0; i < 9999999; i++)
{
try
{
 lock_guard<mutex> lck(mtx);
rethrow_exception(ex);
}
catch(...)
{
 current_exception(); // <- run concurrently
}
}
}
void test()
{
 exception_ptr ex;

try
{
 throw runtime_error("O_o");
}
catch(...)
{
 // use current_exception() it's compulsory condition
 // because only in this case will be used unsafe detail::refcount_ptr
 // (in current_exception_std_exception_wrapper inherited from exception)
 ex = current_exception();
}

 mutex mtx;
 vector<shared_ptr> > group;
 for(int i = 0; i < 10; i++)
 group.push_back(shared_ptr<thread>(new thread(bind(executer, ref(mtx), ex))));

 vector<shared_ptr> >::iterator it = group.begin();
 for(; it != group.end(); it++)
(*it)->join();
}

void version()
{
#ifdef __GXX_EXPERIMENTAL_CXX0X__
 cout << "use c++11 implementation\n";
#else
 cout << "use the boost implementation\n";
#endif
}

int main()
{
version();
 cout << "Start\n";

test();

 cout << "Exit\n";
}
</shared_ptr></thread></shared_ptr></mutex></boost></boost></memory></future></thread></vector></stdexcept></exception></iostream>

this example falls down if you use boost and does not drop if you use the std implementation (-std=c++11).

Standard on this occasion wrote the following

18.8.5 Exception propagation ... For purposes of determining the presence of a data race, operations onexception_ptr objects shall access and modify only the exception_ptrobjects themselves and not the exceptions they refer to. Use of rethrow_exceptionon exception_ptr objects that refer to the same exception object shallnot introduce a data race. [Note: if rethrow_exception rethrows the same exception object (ratherthan a copy), concurrent access to that rethrown exception object may introduce a data race. Changesin the number ofexception_ptrobjects that refer to a particular exception do not introduce a datarace.—end note]

What is described in the note this is just my situation, but I do not understand as it should be and so should not be?

October 3rd 19 at 02:07

Find more questions by tags BoostC++