TDPL, std.concurrency and OwnerFailed

Ali Çehreli acehreli at yahoo.com
Tue Sep 3 10:58:24 PDT 2013


On 09/03/2013 09:26 AM, Alexandr Druzhinin wrote:

 > OwnerFailed exception catching like TDPL says, but std.concurrency has
 > no such symbol.

These are the ones that I am aware of at this time:

   MessageMismatch
   OwnerTerminated
   LinkTerminated
   MailboxFull
   PriorityMessageException

 > So, something changed. Can somebody help me with this
 > case - finding if a child thread finished/terminated?

One way is, the child can send a special message (even the exception 
itself) when it terminates:

// ... at the worker ...
                 try {
                     // ...

                 } catch (shared(Exception) exc) {
                     owner.send(exc);
                 }},

Beware though: There has been problems with "disappearing workers" even 
with that code. The reason is, the code above does not catch Errors. 
However, if it did catch by Error (or, more generally by Throwable), 
then in theory, it shouldn't trust program state sufficiently to be able 
to send a message to the owner.

 > I know about spawnLinked, but I want to get known about child state when
 > sending, not receiving, because in the last case I don't know what of
 > linked child threads is terminated.

I don't think it is a complete solution: Even if you think the child is 
healthy when you send the message, it may terminate right after 
receiving it.

Ali



More information about the Digitalmars-d-learn mailing list