Endless static this call when used a thread in it

tcak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 13 05:56:05 PST 2015


On Tuesday, 13 January 2015 at 13:53:11 UTC, tcak wrote:
> I have written the following code:
>
> test.d
> ==============================
> import core.thread;
> import std.stdio;
>
> void threadFunc(){
> 	writeln("Thread func");
> }
>
> public static this(){
> 	auto t = new Thread( &threadFunc );
> 	t.start();
>
> 	writeln("Static init");
> }
>
> void main(){
>      writeln("End of main");
> }
>
>
> run
> ======================
> rdmd test.d
>
>
> result
> ======================
> Static init
> Thread func
> Static init
> Thread func
> Static init
> Thread func
> Static init
> Thread func
> Static init
> Thread func
> Static init
> Thread func
> Static init
> Thread func
> Static init
> Thread func
> Sta...
>
> Is this normal, what's happening?

When I defined static init with shared

public shared static this()

it works normal now. But it doesn't explain above issue. What's 
the relation between a new thread and a module's initialiser?


More information about the Digitalmars-d-learn mailing list