Bug 23831 – [GC] support option to always run dtor in allocating thread

Status
NEW
Severity
enhancement
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-04-06T14:11:17Z
Last change time
2024-12-07T13:42:35Z
Assigned to
No Owner
Creator
Steven Schveighoffer
Moved to GitHub: dmd#17459 →

Comments

Comment #0 by schveiguy — 2023-04-06T14:11:17Z
In certain cases, it might be be advantageous to ensure a destructor runs in the same thread as the allocation. For example, if the destructor uses TLS. The idea I have is: 1. Add a new GC bit for "dtor locked to thread" for blocks with a destructor. 2. Preallocate enough memory to allow management of the blocks (i.e. linked list pointer, owning thread id) 3. When a block is detected as garbage, instead of finalizing/freeing the block, add it as a block to destroy inside the thread (using linked list). 4. Upon the next GC call inside the thread (or upon upon destruction), whenever the GC lock is taken, see if there are any local blocks to destroy, and destroy them, then free the blocks. The cost would be another bitset per pool, and extra space to manage the blocks. The allocations need to be done via a new API, since the bit would assume the block is properly instrumented. How that API looks is up for discussion.
Comment #1 by robert.schadek — 2024-12-07T13:42:35Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17459 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB