Strange exception using threads

Ali Çehreli acehreli at yahoo.com
Sat Jun 23 09:29:50 PDT 2012


On 06/23/2012 09:05 AM, Minas Mina wrote:
 > I am using a secondary thread to send messages to it so it can print
 > those messages.

 > std.concurrency.OwnerTerminated at std/concurrency.d(248): Owner terminated

The OwnerTerminated exception is thrown when a worker attempts to 
receive a message to notify it about the fact that its owner has been 
terminated.

There are ways to deal with the situation:

- The worker can catch this particular exception

- The worker can catch this exception as a message

- The owner can send a special YouAreDone :) message to the worker so it 
no longer attempts to receive messages and exits gracefully

- More?

Here is the second method as described in TDPL's concurrency chapter, 
which is available online:

   http://www.informit.com/articles/article.aspx?p=1609144

void writer()
{
     bool done = false;

     while( !done )
     {
         receive(
             (Tid id, int i)
             {
                 writeln("Secondary thread: ", i);
             },

             (OwnerTerminated exc) // <----- as a message
             {
                 done = true;
             }
         );
     }
}

Ali

-- 
D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html



More information about the Digitalmars-d-learn mailing list