From d525286b0f7c8caa98042811db42af3e77d0307f Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 18 Jan 2021 18:18:30 +0000 Subject: [PATCH] smartthreadpool: do informcomleted under locks --- ThirdParty/SmartThreadPool/SmartThreadPool.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ThirdParty/SmartThreadPool/SmartThreadPool.cs b/ThirdParty/SmartThreadPool/SmartThreadPool.cs index c2a0d6dd62..40394a6c7d 100644 --- a/ThirdParty/SmartThreadPool/SmartThreadPool.cs +++ b/ThirdParty/SmartThreadPool/SmartThreadPool.cs @@ -665,6 +665,7 @@ namespace Amib.Threading // of the dictionary. CurrentThreadEntry = _workerThreads[Thread.CurrentThread]; + bool informedCompleted = false; FireOnThreadInitialization(); try @@ -689,7 +690,8 @@ namespace Amib.Threading // This method must be called within this lock or else // more threads will quit and the thread pool will go // below the lower limit. - //InformCompleted(); + InformCompleted(); + informedCompleted = true; break; } } @@ -700,7 +702,6 @@ namespace Amib.Threading // Wait for a work item, shutdown, or timeout WorkItem workItem = Dequeue(); - // On timeout or shut down. if (workItem == null) { @@ -715,7 +716,8 @@ namespace Amib.Threading // This method must be called within this lock or else // more threads will quit and the thread pool will go // below the lower limit. - //InformCompleted(); + InformCompleted(); + informedCompleted = true; break; } } @@ -814,7 +816,8 @@ namespace Amib.Threading } finally { - InformCompleted(); + if(!informedCompleted) + InformCompleted(); FireOnThreadTermination(); _workItemsQueue.CloseThreadWaiter(); }