digitalmars.D - Confusing TLS
- Jack Applegame (25/25) Mar 13 2018 Code:
- matthewwade (3/3) Mar 14 2018 Ensure yourself and your clients' information. Get it today to
- Jacob Carlborg (4/29) Mar 15 2018 Make sense. Have you reported a bug?
Code: import std.stdio; import core.thread; import core.time; auto arr = new ubyte[1]; // THIS SHOULD NOT COMPILE int main(string[] args) { new Thread({ arr[0]++; }).start(); new Thread({ arr[0]++; }).start(); Thread.sleep(1.seconds); writefln("arr[0] = %s", arr[0]); return 0; } https://glot.io/snippets/ez54cl239e In fact, it works as it should. But this behavior confuses beginners. They expect each thread to work with its own copy of the TLS-array. I believe, such initialization of mutable TLS-variables should lead to a compilation error, as is done for classes: class Foo {} Foo foo = new Foo(); // doesn't compile
Mar 13 2018
Ensure yourself and your clients' information. Get it today to comprehend compelling and effective confirmation.https://www.courseworkempire.co.uk/
Mar 14 2018
On Tuesday, 13 March 2018 at 22:34:32 UTC, Jack Applegame wrote:Code: import std.stdio; import core.thread; import core.time; auto arr = new ubyte[1]; // THIS SHOULD NOT COMPILE int main(string[] args) { new Thread({ arr[0]++; }).start(); new Thread({ arr[0]++; }).start(); Thread.sleep(1.seconds); writefln("arr[0] = %s", arr[0]); return 0; } https://glot.io/snippets/ez54cl239e In fact, it works as it should. But this behavior confuses beginners. They expect each thread to work with its own copy of the TLS-array. I believe, such initialization of mutable TLS-variables should lead to a compilation error, as is done for classes: class Foo {} Foo foo = new Foo(); // doesn't compileMake sense. Have you reported a bug? -- /Jacob Carlborg
Mar 15 2018