Bug 22412 – std.parallelism WorkerLocalStorage calls struct destructors on uninitialized memory

Status
NEW
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2021-10-17T19:27:08Z
Last change time
2024-12-01T16:39:34Z
Assigned to
No Owner
Creator
duser
Moved to GitHub: phobos#10482 →

Comments

Comment #0 by duser — 2021-10-17T19:27:08Z
--- 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
Comment #1 by robert.schadek — 2024-12-01T16:39:34Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10482 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB