[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 10:11:45 PDT 2017


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

--- Comment #7 from Mathias Lang <mathias.lang at sociomantic.com> ---
When a thread runs I would expect the following (simplified) course of action:
- Initialize the TLS data
- Do the writeln
- Exit

Given the original code, I would then expect the code to print 3 times
"/some/string/initializer" and one time "foobar". I would not expect any order.

Which means the first 2 runs give a perfectly valid output. However, the 3rd
run outputs "/some/string/initializer" twice, and "foobar" twice. How can
"foobar" be printed twice if it's only set for one thread ? If the delegate
generated from the `foreach` body would capture the static instance of the main
thread, we would get 4 "foobar". but we don't.

--


More information about the Digitalmars-d-bugs mailing list