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

Commit 8a61b43

Browse files
committed
Fix issue 17413: Prevent deadlock in the GC init
If the program during initialization in the pressing memory environment died with the Error thrown by the GC, GC would not be usable anymore. However, dso registry unregistration will try to removeRanges. This would cause a deadlock in the GC, preventing the exit of the program. This commit prevents GC entering the recursive lock from the chain GC.fullcollect() -> Error -> dso_registry -> GC.removeRange.
1 parent d5088da commit 8a61b43

File tree

1 file changed

+4
-1
lines changed
  • src/gc/impl/conservative

1 file changed

+4
-1
lines changed

src/gc/impl/conservative/gc.d

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ class ConservativeGC : GC
10931093

10941094
void removeRange(void *p) nothrow @nogc
10951095
{
1096-
if (!p)
1096+
if (!p || _isLocked)
10971097
{
10981098
return;
10991099
}
@@ -2374,12 +2374,14 @@ struct Gcx
23742374

23752375
{
23762376
// lock roots and ranges around suspending threads b/c they're not reentrant safe
2377+
ConservativeGC._isLocked = true;
23772378
rangesLock.lock();
23782379
rootsLock.lock();
23792380
scope (exit)
23802381
{
23812382
rangesLock.unlock();
23822383
rootsLock.unlock();
2384+
ConservativeGC._isLocked = false;
23832385
}
23842386
thread_suspendAll();
23852387

@@ -2395,6 +2397,7 @@ struct Gcx
23952397
markAll(nostack);
23962398

23972399
thread_processGCMarks(&isMarked);
2400+
ConservativeGC._isLocked = false;
23982401
thread_resumeAll();
23992402
}
24002403

0 commit comments

Comments
 (0)