Thread termination conditions in dmd 2.064.2

Atila Neves atila.neves at gmail.com
Thu Nov 7 02:21:56 PST 2013


I had code that worked in 2.063 that crashes now (on Linux, on 
Windows it still works). I suspect I was doing something stupid 
and got lucky, but I'm posting here to make sure. Code:

import std.concurrency;

private void func() {
     auto done = false;

     while(!done) {
         receive(
             (OwnerTerminated trm) {
                 done = true;
             }
         );
     }
}

void main() {
     spawn(&func);
}

Changing func like so stops the crashing (which I agree is better 
code anyway that I just shamelessly stole from TDPL):

private void func() {
     for(auto running = true; running;) {
         receive(
             (OwnerTerminated trm) {
                 running = false
             }
         );
     }
}


So what's going on? I thought it maybe had to do with 
synchronisation but doing the write in a synchronized block 
changed nothing. Bug or me being stupid?

Atila





More information about the Digitalmars-d-learn mailing list