Bug 23593 – core.thread: suspendAll doesn't wait for all if current thread has detached itself

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
FreeBSD
Creation time
2022-12-31T00:06:38Z
Last change time
2022-12-31T01:13:02Z
Keywords
pull
Assigned to
No Owner
Creator
Iain Buclaw

Comments

Comment #0 by ibuclaw — 2022-12-31T00:06:38Z
See the following for all the gory details. https://github.com/dlang/dmd/pull/14710 https://github.com/dlang/dmd/pull/14753 https://github.com/dlang/dmd/pull/14754 Essentially --- new Thread({ thread_detachThis(); GC.collect(); }).start(); --- The GC collection will call thread_suspendAll, and as the calling thread detached itself, the suspend counter will be `1` (instead of `2`) - however the counter is decremented before the entering the loop that calls sem_wait until all threads have signalled resume - meaning there's an implicit assumption that the current thread was counted - so it exits immediately rather than waiting for the main thread to respond. This means there's now a race condition between the detached thread running the GC and the main thread setting up the Thread.tstack/bstack values. If the GC scan wins, then the main thread stack won't have any live data marked.
Comment #1 by dlang-bot — 2022-12-31T00:37:31Z
@ibuclaw updated dlang/dmd pull request #14763 "core.thread.osthread: Don't subtract suspend counter if thread has detached itself" fixing this issue: - fix Issue 23593 - core.thread: suspendAll doesn't wait for all if current thread has detached itself. Don't subtract suspend counter if thread has detached itself. https://github.com/dlang/dmd/pull/14763
Comment #2 by dlang-bot — 2022-12-31T01:13:02Z
dlang/dmd pull request #14763 "core.thread.osthread: Don't subtract suspend counter if thread has detached itself" was merged into master: - 096b48eab47b9deca54fc48c96be77675eaca31b by Iain Buclaw: fix Issue 23593 - core.thread: suspendAll doesn't wait for all if current thread has detached itself. Don't subtract suspend counter if thread has detached itself. https://github.com/dlang/dmd/pull/14763