https://issues.dlang.org/show_bug.cgi?id=17476

--- Comment #6 from Andrej Mitrovic <[email protected]> ---
> In main, you set the TLS instance of path corresponding to the main thread to 
> "foobar". The "parallel" loop body will use the current thread's TLS 
> instance, but because the order of execution of threads is of course 
> undefined, you get inconsistent results.

I was initially confused not by the order of things, but by the multiple
printouts of "foobar". However this explains everything:

-----
import std.concurrency;
import std.stdio;
import std.parallelism;

struct Params
{
    static string path = "/some/string/initializer";
}

void main()
{
    Params.path = "foobar";

    foreach (_; parallel([1, 2, 3, 4]))
    {
        writefln("%s %s", thisTid(), Params.path);
    }
}
-----

Tid(7fe4c452e800) foobar
Tid(7fe4c452e800) foobar
Tid(7fe4c452e900) /some/string/initializer
Tid(7fe4c452ea00) /some/string/initializer

It's a non-issue, we were just puzzled at first. :)

--

Reply via email to