TDPL message passing: OwnerFailed?

Martin Drasar drasar at ics.muni.cz
Tue Jan 22 04:26:59 PST 2013


On 22.1.2013 11:08, monarch_dodra wrote:
> I was trying to do a simple program to test message passing.
> 
> Basically, I have 1 owner, and 2 slave threads.
> 
> I'm facing two problems:
> 
> 1 ) First, I want the slaves to be informed of when the master dies in
> an abnormal way.
> 
> TDPL suggest OwnerFailed, but apparently, the out of band exception that
> is thrown is an "OwnerTerminated", which does not allow me to know if
> the termination is "normal" or not.
> 
> Does that mean I have to manually send a message to my slaves to tell
> them master is finished, and have the slaves take "OwnerTerminated" as
> always abnormal?
> 
> 2 ) Ditto, I need the master to be informed of when a slave dies (via
> exception).
> 
> However, no matter what I do, it would appear the master simply isn't
> informed of the death of its slaves. It just keeps running until it
> finishes, at which point it may and/or may not show the exception...
> 

Hi,

wouldn't this help you?

http://dlang.org/phobos/std_concurrency.html#.spawnLinked

According to documentation: Executes the supplied function in a new
context represented by Tid. This new context is linked to the calling
context so that if either it or the calling context terminates a
LinkTerminated message will be sent to the other, causing a
LinkTerminated exception to be thrown on receive(). The owner
relationship from spawn() is preserved as well, so if the link between
threads is broken, owner termination will still result in an
OwnerTerminated exception to be thrown on receive().

Martin


More information about the Digitalmars-d-learn mailing list