Thread overview
Thread termination conditions in dmd 2.064.2
Nov 07, 2013
Atila Neves
Nov 07, 2013
Atila Neves
Nov 07, 2013
Sönke Ludwig
November 07, 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



November 07, 2013
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).
November 07, 2013
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