Mailbox limits and dead/livelocks?

Ali Çehreli acehreli at yahoo.com
Tue Jul 24 08:33:33 PDT 2012


On 07/24/2012 07:46 AM, Enerqi wrote:
 > The actors in std.concurrency - in this example it's non-deterministic
 > whether the process may or may not hang. I'm confused as to why. I have
 > set the mailbox sizes to 1. But the message flow seems simple enough. I
 > don't see how the message limit of 1 is blocking everything, I am
 > catching Variant messages so nothing should be in the mailbox unread.

I have struggled with a similar problem recently. When an apparent 
lock-up occurs, it may be because a worker has terminated, likely by 
assert(). (There has been a thread about exceptions from workers getting 
lost.)

The trick is to start the worker with spawnLinked so that a 
LinkTerminated exception can be received on the owner's side:


         tids[i] = spawnLinked(&blah1, thisTid);
// ...
                 (LinkTerminated exc)
                 {
                     writeln("A worker has terminated: ", exc);
                     // ...
                 },

The other std.concurrency exception that can be received as a message is 
OwnerTerminated:

             (OwnerTerminated exc)
             {
                 writeln("The owner has terminated; exiting.");
                 isDone = true;
             }

I am in the process of updating the following page with the information 
above:

   http://ddili.org/ders/d.en/concurrency.html

Ali



More information about the Digitalmars-d-learn mailing list