[cpp-threads] Issue 1369 --- thread safety of std::rethrow_exception

Jonathan Wakely cxx at kayari.org
Mon Nov 15 23:17:56 GMT 2010


On 15 November 2010 20:56, N.M. Maclaren wrote:
>
> The memory that only the owning thread may access is not allocated by the
> normal C++ mechanisms, in the cases that I have seen.  This is my point
> about needing action to convert an exception from its original form to a
> form that has value semantics (and is no longer the original exception,
> but merely one that looks the same).

C++ exceptions are normal objects with value semantics. 15.1 p3 says:
"the operand of throw is treated exactly as a function argument in a
call (5.2.2) or the operand of a return statement."

In order to throw something, you already need to have something with
value semantics, so by the time it is stored in a std::exception_ptr
and rethrown by std::rethrow_exception you already have something with
value semantics.

> I am surprised about your reference to "stack-allocated data".  I don't
> see how you can allow "value semantics" exceptions to contain any references
> to the stack of the thread that raised the exception and allow them to be
> passed as data to other threads, without a lot of extra constraints that I
> can't find in the standard.  I may have missed those, of course.

I think Hans was talking about parallel algorithms that refer to
stack-allocated data, not exceptions.

e.g.

int data[n];
fill(data, n);
parallel_sort( data, data+n );

As he said, that's a separate issue to exceptions requiring local cleanup.



More information about the cpp-threads mailing list