My understanding is that the general rule for types in the C++ standard library that using them concurrently w/o locking is fine as long as all the concurrent operations are reads
I 'know' that internally, std::exception_ptr
is implemented via some sort of reference counting, so copying it actually involves some sort of write(s), is that an issue for code like the following?
// Global scope
std::exception_ptr GetSharedException() noexcept
{
try
{
static const std::exception_ptr result(std::make_exception_ptr(CreateException()))
return result;
}
catch (...)
{
return std::current_exception();
}
}
// Some function which can be running on multiple threads concurrently
void foo() noexcept
{
// Do stuff
if (bar())
consume(GetSharedException())
// Do more stuff
}