Summary: druntime GC wrongly frees data pointed to by TLS.
           Product: D
           Version: 2.021
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: Phobos
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]

Apparently, under certain circumstances, the D 2.21 druntime GC wrongly frees
memory locations pointed to by thread-local storage.

import core.memory, std.stdio;

__thread Stuff* stuff1;

struct Stuff {
    uint num;

void main() {
    stuff1 = new Stuff;
    stuff1.num = 1;
    auto bar = new byte[1024 * 1024];
    auto stuff2 = new Stuff;
    stuff2.num = 2;
    writeln(stuff1, "\t", stuff2);  // Same address.
    writeln(stuff1.num, "\t", stuff2.num);  // Both 2.

If you disable the GC using GC.disable at the top of main() or change stuff1 to
a non-thread-local, the problem goes away.


Reply via email to