S
Scott Meyers
Suppose I run a couple of functions in parallel, catching an exception if either
throws. If both throw, I want to catch one of the exceptions, but I don't care
which one. I might try this:
std::exception_ptr xp;
std::async([&]{
try { doThis(); }
catch(...) { xp = std::current_exception(); }
});
std::async([&]{
try { doThat(); }
catch(...) { xp = std::current_exception(); }
});
if (xp) {
// at least one of the tasks above threw
}
This can work only if assignment to xp (i.e., a std::exception_ptr object) is
thread-safe. I see no such guarantee in draft C++0x, but I'm hoping I'm
overlooking something. Is there any reason to believe that assignment to a
std::exception_ptr object is thread-safe?
Thanks,
Scott
throws. If both throw, I want to catch one of the exceptions, but I don't care
which one. I might try this:
std::exception_ptr xp;
std::async([&]{
try { doThis(); }
catch(...) { xp = std::current_exception(); }
});
std::async([&]{
try { doThat(); }
catch(...) { xp = std::current_exception(); }
});
if (xp) {
// at least one of the tasks above threw
}
This can work only if assignment to xp (i.e., a std::exception_ptr object) is
thread-safe. I see no such guarantee in draft C++0x, but I'm hoping I'm
overlooking something. Is there any reason to believe that assignment to a
std::exception_ptr object is thread-safe?
Thanks,
Scott