From c8331f13a0cdbbbec9540875e6af1514f09de917 Mon Sep 17 00:00:00 2001 From: Bernhard Seckinger Date: Wed, 11 Dec 2019 14:19:09 +0100 Subject: [PATCH] Fix Issue 20160 - ThreadInfo.cleanup() clears local thread's registered names instead of "this"'s --- std/concurrency.d | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/std/concurrency.d b/std/concurrency.d index e3258268a..a563f3b6d 100644 --- a/std/concurrency.d +++ b/std/concurrency.d @@ -994,18 +994,17 @@ private @property Mutex registryLock() return impl; } -private void unregisterMe() +private void unregisterMe(ref ThreadInfo me) { - auto me = thisInfo.ident; - if (thisInfo.ident != Tid.init) + if (me.ident != Tid.init) { synchronized (registryLock) { - if (auto allNames = me in namesByTid) + if (auto allNames = me.ident in namesByTid) { foreach (name; *allNames) tidByName.remove(name); - namesByTid.remove(me); + namesByTid.remove(me.ident); } } } @@ -1128,7 +1127,18 @@ struct ThreadInfo _send(MsgType.linkDead, tid, ident); if (owner != Tid.init) _send(MsgType.linkDead, owner, ident); - unregisterMe(); // clean up registry entries + unregisterMe(this); // clean up registry entries + } + + // issue 20160 + @system unittest + { + register("main_thread", thisTid()); + + ThreadInfo t; + t.cleanup(); + + assert(locate("main_thread") == thisTid()); } }