smartthreadpool: do informcomleted under locks

This commit is contained in:
UbitUmarov
2021-01-18 18:18:30 +00:00
parent 545e196226
commit d525286b0f

View File

@@ -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();
}