From 08835c01cf2d64a06c53739223edba55cc23db2f Mon Sep 17 00:00:00 2001 From: Mihails Strasuns Date: Thu, 6 Apr 2017 13:56:47 +0200 Subject: [PATCH] Simple multithreaded program + "-profile=gc" = crash Fixes issue 15947 (https://issues.dlang.org/show_bug.cgi?id=15947) Fixes issue 14511 (https://issues.dlang.org/show_bug.cgi?id=14511) Root problem was trying to increment non-existent AA field upon merging profile stats. The code was also simplified to remove unnecessary condition. --- src/rt/profilegc.d | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/rt/profilegc.d b/src/rt/profilegc.d index a3c5ce6235..a5ec1a8396 100644 --- a/src/rt/profilegc.d +++ b/src/rt/profilegc.d @@ -89,18 +89,14 @@ static ~this() { synchronized { - if (globalNewCounts.length) + foreach (name, entry; newCounts) { - // Merge - foreach (name, entry; newCounts) - { - globalNewCounts[name].count += entry.count; - globalNewCounts[name].size += entry.size; - } + if (!(name in globalNewCounts)) + globalNewCounts[name] = Entry.init; + + globalNewCounts[name].count += entry.count; + globalNewCounts[name].size += entry.size; } - else - // Assign - globalNewCounts = newCounts; } newCounts = null; }