std.concurrency and module constructors
Simen Kjaeraas
simen.kjaras at gmail.com
Fri May 11 06:19:48 PDT 2012
On Fri, 11 May 2012 14:56:03 +0200, japplegame <japplegame at gmail.com>
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...
More information about the Digitalmars-d-learn
mailing list