[dmd-concurrency] draft 6

Michel Fortin michel.fortin at michelf.com
Thu Jan 28 12:17:00 PST 2010


Le 2010-01-28 à 13:48, Andrei Alexandrescu a écrit :

> Michel Fortin wrote:
>> Le 2010-01-28 à 11:18, Andrei Alexandrescu a écrit :
>>>>> If a thread exits via an exception, the exception OwnerFailed propagates to all of its owned threads by means of prioritySend.
>>>> I though we were in agreement that it'd be better if this was handled serially by default to avoid races in the program's logic?
>>> I think it's fine to propagate serially on _success_ but not on failure. Failure has priority.
>> I argued previously that this is what you want sometime, but not always. If you were "copying" your file by sending its content to a browser and a failure happens while reading the end of the file, you'd want to continue sending the file up to the error point. On the
>> other side if you're copying to another file, you might want to delete the partial copy in case of failure. In the later case, sending the event faster is an optimization, in the first case, it is
>> not even desirable.
> 
> It's all a matter of defaults. You can choose to catch the exception and send it without priority.

It's just that in my view, defaults should be the safer choice. It's much easier to add an optimization (an asynchronous message) where you know need it than explicitly remove it everywhere where it could be a problem.


>> That only partially address my point. In the thread termination protocol I wrote, if a thread terminates with an uncaught exception, that exception is sent back to the owner thread (and you'd get it on a call to receive). Have you decided not to do any of this?
> 
> I don't know. Erlang offers a different primitive spawn_link for explicitly making the parent receive exceptions from the child. The default is the parent doesn't care.

It's again a problem of choosing the right defaults. :-)

My only fear is that if you only rarely send messages to a thread, and that thread crashes, it could take a long time before the program takes notice (probably the next time someone attempts to send a message). I don't think errors should be ignored by default.

I remember working with a heavily multithreaded C++ program where we sometime had threads crashing from unhanded exceptions. In those cases the program was often continuing as usual, only with unintended behaviours or with some things becoming non-functionnal, or crashing a little while later. In any case, it is not fun to debug.

That's why I believe such exceptions should be propagated back to the owner thread. The effect would be mostly like what exceptions do with the stack: progressively "unwind" the thread ownership hierarchy until one thread handles the exception

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/





More information about the dmd-concurrency mailing list