[Issue 17476] Static fields don't seem to be reliably initialized when using parallel()

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 7 09:23:06 PDT 2017


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

Vladimir Panteleev <thecybershadow at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |thecybershadow at gmail.com
         Resolution|---                         |INVALID

--- Comment #3 from Vladimir Panteleev <thecybershadow at gmail.com> ---
No bug here.

path in a TLS variable, so there is one instance per thread.

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'm not sure what you expect - that the order of thread execution is
deterministic? This is of course impossible. Or do you want one instance of
"path" per the entire program, shared across threads? Then move it out of the
TLS into the stack or data segment (but watch out for data races).

--


More information about the Digitalmars-d-bugs mailing list