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

Commit

Permalink
fix issue 20219 - Idle D programs keep consuming CPU in Gcx.scanBackg…
Browse files Browse the repository at this point in the history
…round

background scan threads now wait indefinitely, with termination continuously triggering the condition until all threads have woken up
  • Loading branch information
rainers committed Sep 17, 2019
1 parent 50888c7 commit 85b293f
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/gc/impl/conservative/gc.d
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,7 @@ struct Gcx
Event evDone;

shared uint busyThreads;
shared uint stoppedThreads;
bool stopGC;

void markParallel(bool nostack) nothrow
Expand Down Expand Up @@ -2830,8 +2831,17 @@ struct Gcx
return;

debug(PARALLEL_PRINTF) printf("stopScanThreads\n");
int startedThreads = 0;
for (int idx = 0; idx < numScanThreads; idx++)
if (scanThreadData[idx].tid != scanThreadData[idx].tid.init)
startedThreads++;

stopGC = true;
evStart.set();
while (atomicLoad(stoppedThreads) < startedThreads)
{
evStart.set();
evDone.wait(dur!"msecs"(1));
}

for (int idx = 0; idx < numScanThreads; idx++)
{
Expand All @@ -2856,10 +2866,11 @@ struct Gcx
{
while (!stopGC)
{
evStart.wait(dur!"msecs"(10));
evStart.wait();
pullFromScanStack();
evDone.set();
}
stoppedThreads.atomicOp!"+="(1);
}

void pullFromScanStack() nothrow
Expand Down

0 comments on commit 85b293f

Please sign in to comment.