On Fri, 11 May 2012 14:56:03 +0200, japplegame <[email protected]> wrote:

OS: Windows 7 64bit
Compiler: DMD32 D Compiler v2.059

Using spawn in module constructor causes very strange behavior.

import std.concurrency;
import std.stdio;
void main() {
}
void worker() {
   receiveOnly!OwnerTerminated;
}
static this() {
   writeln("module constructor");
   spawn(&worker);
}
static ~this() {
   writeln("module destructor");
}

prints in console:

module constructor
module destructor
module constructor
module destructor
module constructor
module constructor
module constructor
module constructor
module constructor
...

Indeed it does. spawn creates a new thread, which has to construct its own
modules (things are thread-local in D, after all). Doing so calls spawn again,
which creates a new thread...

Reply via email to