TDPL message passing: OwnerFailed?

monarch_dodra monarchdodra at gmail.com
Tue Jan 22 02:08:43 PST 2013


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...

//----
import std.concurrency, std.stdio;
import core.thread;

void main()
{
     auto tid1 = spawn(&fileWriter1);
     auto tid2 = spawn(&fileWriter2);

     Thread.sleep(dur!"seconds"(1));

     send(tid1, 1);
     send(tid2, 2);

     stderr.writeln("Normally master.");
}

void fileWriter1() {
     throw new Exception("Bwah ha ha 1!");
}

void fileWriter2() {
     throw new Exception("Bwah ha ha 2!");
}
//----
Normally master.
//----

If I remove the sleep, I get:
//----
Normally master.
object.Exception at main.d(20): Bwah ha ha 2!
//----

FYI, the original project was writing a file writer that takes 1 
input, and 2 outputs. THis is rather easy, but the error handling 
is eluding me.


More information about the Digitalmars-d-learn mailing list