Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Fix issue 17413: Prevent deadlock in the GC init #1872

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/gc/impl/conservative/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ class ConservativeGC : GC

void removeRange(void *p) nothrow @nogc
{
if (!p)
if (!p || _isLocked)
{
return;
}
Expand Down Expand Up @@ -2374,12 +2374,14 @@ struct Gcx

{
// lock roots and ranges around suspending threads b/c they're not reentrant safe
ConservativeGC._isLocked = true;
rangesLock.lock();
rootsLock.lock();
scope (exit)
{
rangesLock.unlock();
rootsLock.unlock();
ConservativeGC._isLocked = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From your description the failure seems to be that we're not unlocking those ranges on failure, so it's just broken cleanup on Error, but setting the reentrant flag is quite an ugly hackaround.
An explicit try / catch (Error) / cleanup / rethrow works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, of course. I'll update.

}
thread_suspendAll();

Expand All @@ -2395,6 +2397,7 @@ struct Gcx
markAll(nostack);

thread_processGCMarks(&isMarked);
ConservativeGC._isLocked = false;
thread_resumeAll();
}

Expand Down