[cpp-threads] Re: Exception propogation across threads

Paul E. McKenney paulmck at linux.vnet.ibm.com
Wed Feb 21 22:37:27 GMT 2007


On Wed, Feb 21, 2007 at 10:09:21PM +0000, Kevlin Henney wrote:
> Paul E. McKenney <paulmck at linux.vnet.ibm.com> writes
> >
> >I am uncharacteristically with Hans on this one.  ;-)
> >
> >Here is the scenario that I am concerned about:
> >
> >o      A threaded "server" application with indefinite lifetime.
> >
> >o      One of the threads encounters a bug that results in an
> >      exception.
> >
> >o      The rest of the server sort of runs along, but with strange
> >      behavior due to the dead thread.
> >
> >Seems like it would be better to just kill the whole process.
> 
> Agreed. Therefore, register a handler that does this. Problem solved, 
> clearly and explicitly :-)

OK, but I thought that the issue before us dealt with the situation when
there was no such handler.  And having an error condition be indetectable
until one brings the application down does not seem at all reasonable to
me as a default for the common situation where there are no handlers.

> >If the
> >developer would prefer to make the failure known at join() time, it is
> >pretty easy to put in top-level exception handlers, right?
> 
> Actually, no it isn't: a top-level exception handler in the executing 
> thread will stop an exception in the thread, but it won't propagate it 
> across a join. You need plumbing to do this, hence the reason to favour 
> a model that takes this into account rather than one that is oblivious 
> to it.
> 
> The bias to date in considering a programming model for threads has been 
> to treat thread executors as launching functions and function objects, 
> all of which are reasonably entitled to throw exceptions. This point of 
> view more closely aligns with the idea that an exception that leaves a 
> function should not be in the business of killing a process by default, 
> which makes more sense for coarse-grained threading whose failure you 
> consider critical, and therefore need to make a special point of 
> highlighting.
> 
> I am concerned that making total process death the chosen behaviour 
> shows a default bias towards coarse-grained threading, just as we are 
> moving into the era of fine-grained threading. As I said before, killing 
> the whole process seems unnecessarily severe: feel free to consider it 
> an option, but we should avoid imposing what some (myself included) 
> might consider to be unreasonable defaults.

So you want some way of being able to propagate exceptions into the parent
thread.  I don't have a problem with that, as long as it is not the default
behavior.  I suppose the "right" thing to do would be to have another
pthread_attr_t attribute...

						Thanx, Paul



More information about the cpp-threads mailing list