On Tuesday, 22 August 2017 at 15:52:48 UTC, Kagamin wrote:
On Tuesday, 22 August 2017 at 14:53:21 UTC, Moritz Maxeiner wrote:
There is a bug [1] - as others have pointed out - that the static array isn't stored in TLS, but in global storage, however, but that doesn't apply in this single threaded case.

The initializer is copied from typeinfo, that can't refer to TLS data.

Which means it isn't easily fixable (or even feasible). I'd still consider it a loophole in the type system right now as it allows declaring global data mutably shared between threads without `shared` or `__gshared` (the latter of which couldn't be applied here, though). I'd argue that - as new in this case doesn't allocate on the heap, but in the resulting application's appropriate segments) - it should work like this (from a language semantics standpoint):

---

class Test
{
shared(ubyte)[] buf = new shared(ubyte)[1000]; // classic global storage, instances in all threads refer to the same static array
}

class Test
{
ubyte[] buf = new ubyte[1000]; // thread local storage, instances in the same thread refer to the same static array
}
---

Reply via email to