www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22412] New: std.parallelism WorkerLocalStorage calls struct

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

          Issue ID: 22412
           Summary: std.parallelism WorkerLocalStorage calls struct
                    destructors on uninitialized memory
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: duser airmail.cc

---
import std;

struct zero
{
        char x;
        ~this() { writefln("~zero() 0x%x '%s'   0x%s", x, x, &this); }
}

void main()
{
        std.parallelism.defaultPoolThreads(1);
        writeln(">>>");
        auto wls = taskPool.workerLocalStorage!zero;
        writeln("<<<");
        writeln(wls);
}
---

output:

---
% dmd -run test.d

~zero() 0x0 '' 0x7FFCD1506318 ~zero() 0x0 '' 0x7FFCD1506318 ~zero() 0xff '�' 0x7FFCD1506358 ~zero() 0xff '�' 0x7FFCD15063E9 ~zero() 0xff '�' 0x7FFCD1506358 ~zero() 0xff '�' 0x7FFCD15063E9 <<< WorkerLocalStorage!(zero)(std.parallelism.TaskPool, 2, 64, 7FA458F92010, 7FA458F94040) --- relevant line: https://github.com/dlang/phobos/blob/v2.098.0/std/parallelism.d#L3095 it seems to be calling T's destructor on the newly allocated memory when setting it to T.init. i don't think it should be calling the destructor at all when there couldn't have been a valid T in the memory there --
Oct 17 2021