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

Commit

Permalink
Fix issue 17413: Prevent deadlock in the GC init
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Burgos committed Jul 13, 2017
1 parent d5088da commit 224e35c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 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;
}
thread_suspendAll();

Expand Down

0 comments on commit 224e35c

Please sign in to comment.