Thread overview | |||||
---|---|---|---|---|---|
|
September 03, 2013 TDPL, std.concurrency and OwnerFailed | ||||
---|---|---|---|---|
| ||||
Hello I try to get known if daughter thread finished its work using OwnerFailed exception catching like TDPL says, but std.concurrency has no such symbol. So, something changed. Can somebody help me with this case - finding if a child thread finished/terminated? 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. |
September 03, 2013 Re: TDPL, std.concurrency and OwnerFailed | ||||
---|---|---|---|---|
| ||||
Posted in reply to Alexandr Druzhinin | 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 |
September 04, 2013 Re: TDPL, std.concurrency and OwnerFailed | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | 04.09.2013 0:58, Ali Çehreli пишет: > 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); > }}, > This implies some protocol, at least simplest, but hand-made, non-standard protocol - I'd like to avoid this if possible and use standart ways > 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. But if after catching Throwable and sending a message to the parent I stop the worker - I won't be needed to trust a worker state, because it won't be used more? Or again I need some protocol to avoid this case? > > > 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. You're absolutely right. So, ultimately I need some communication protocol. It would be very nice if phobos has something like message pattern in zeromq. |
Copyright © 1999-2021 by the D Language Foundation