[cpp-threads] Re: Exception propogation across threads

Kevlin Henney kevlin at curbralan.com
Wed Feb 21 19:14:05 GMT 2007


"Meredith, Alisdair" <Alisdair.Meredith at uk.renaultf1.com> writes
>
>At the Portland meeting there were a couple of papers on the idea of
>what happens when a thread fails to catch an exception.
>
>This seemed a much more open question than originally thought, as it was
>not entirely clear what behaviour was expected, although all papers
>proposed a mechanism to propagate the exception across a join.
>
>Is there yet a consensus view on what the desired behaviour is?
>
>i/ terminate whole process, just as when main() fails to catch an
>exception
>ii/ terminate the thread, stack unwinding would be implementation
>defined, but otherwise leave process intact
>iii/ unwind the stack, and hold exception in abeyance somewhere -
>rethrow on join
>iv/ implementation defined stack unwinding - hold exception in abeyance
>somewhere - rethrow on join
>v/ undefined behaviour
>vi/ any of the options I missed ...

Unwind the stack, terminate the thread and throw some kind of unexpected 
thread-death exception in the joining thread. Less severe than (i) and 
(ii), less compiler magic or modification of exceptions needed than 
(iii) and (iv), and more usable than (v).

>The same question needs to be asked of any mechanism that can call abort
>or exit today - e.g. violating an exception specification, throwing
>while an exception is propagating, throwing from destructor of
>Thread-duration objects (n2147), ...

I believe that the question may actually be slightly different in each 
case, but yes it does need to be asked. In the case of an exception 
escaping main, we are saying that the exception has left the building 
and that's it, game over. I would expect this to remain unchanged. For 
threads that do not define the lifetime of the program execution, this 
would be less reasonable. In terms of what to do when violating an 
exception specification, it is harder to generalise or make concrete 
statements about what is or is not actually practical, as I don't think 
there is actually that much experience in what would be the right thing 
to do in that case, and I don't know how many systems rely on current 
behaviour. That one's actually a bit nebulous :-}

>I had intended to write a summary paper on what happened at Portland,
>but it would be meaningless without starting from the answer to the
>question above.

Indeed.

Kevlin
-- 
____________________________________________________________

   Kevlin Henney                   phone:  +44 117 942 2990
   mailto:kevlin at curbralan.com     mobile: +44 7801 073 508
   http://www.curbralan.com        fax:    +44 870 052 2289
   Curbralan: Consultancy + Training + Development + Review
____________________________________________________________




More information about the cpp-threads mailing list