www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13646] New: static darray & pointer initializers always

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

          Issue ID: 13646
           Summary: static darray & pointer initializers always allocated
                    in shared(global) memory rather than in TLS
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: DMD
          Assignee: nobody puremagic.com
          Reporter: floating.point rambler.ru

import std.stdio, std.parallelism;

int[] buf = [1]; // int* buf = [1];

void main(){
    writeln("tls var addr = ", &buf,", ptr = ", buf.ptr, ", value = ", buf[0],"
in main before");

    auto task = task!fun();
    task.executeInNewThread();
    task.yieldForce();

    writeln("tls var addr = ", &buf,", ptr = ", buf.ptr, ", value = ", buf[0],"
in main after");
}
void fun ()  {
    writeln("tls var addr = ", &buf,", ptr = ", buf.ptr, ", value = ", buf[0],"
in child before");
    buf[0] = 2;
    writeln("tls var addr = ", &buf,", ptr = ", buf.ptr, ", value = ", buf[0],"
in child after");
}

produce output:
tls var addr = 1B21A0, ptr = 425080, value = 1 in main before
tls var addr = 1C93E8, ptr = 425080, value = 1 in child before
tls var addr = 1C93E8, ptr = 425080, value = 2 in child after
tls var addr = 1B21A0, ptr = 425080, value = 2 in main after

where 2 independent variables points to same global data

--
Oct 22 2014