www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Thread termination conditions in dmd 2.064.2

reply "Atila Neves" <atila.neves gmail.com> writes:
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
Nov 07 2013
parent reply "Atila Neves" <atila.neves gmail.com> writes:
Looking like a bug I think. Changed the code to this and it 
crashes again:

import std.concurrency;

private void threadWriter() {
     for(bool running = true; running;) {
         receive(
             (Tid i) {
             },
             (OwnerTerminated trm) {
                 running = false;
             }
         );
     }
}

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


This is on Arch Linux 64-bit with the latest package BTW (updated 
this morning).
Nov 07 2013
parent =?UTF-8?B?U8O2bmtlIEx1ZHdpZw==?= <sludwig outerproduct.org> writes:
Am 07.11.2013 11:28, schrieb Atila Neves:
 Looking like a bug I think. Changed the code to this and it crashes again:

 import std.concurrency;

 private void threadWriter() {
      for(bool running = true; running;) {
          receive(
              (Tid i) {
              },
              (OwnerTerminated trm) {
                  running = false;
              }
          );
      }
 }

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


 This is on Arch Linux 64-bit with the latest package BTW (updated this
 morning).
Possibly related: https://github.com/rejectedsoftware/vibe.d/issues/371
Nov 07 2013