-
Notifications
You must be signed in to change notification settings - Fork 181
Open
Description
SmartThreadPool v2.2.3
This finding is very rare, I've encountered this problem only a couple of times so far. Therefore, It's very hard to reproduce.
On some occasions the WaitForIdle doesn't wait with callbacks on the queue. It seems like the ManualResetEvent was Set() or the underlying state changed somehow when it shouldn't have been.
To simulate this problem uncomment the call to StpChangeState().
The behavior with StpChangeState() uncommented is consistent with what I'm occasionally encountering.
Any idea what may be causing this? Has this problem been reported before?
using (var stp = new SmartThreadPool(new STPStartInfo
{ MinWorkerThreads = 0, MaxWorkerThreads = 2, StartSuspended = false }))
{
do
{
stp.QueueWorkItem(JobOne, stp);
stp.QueueWorkItem(JobTwo, stp);
Thread.Sleep(20);
// Uncomment this line to simulate the problem
// StpChangeState(stp);
stp.WaitForIdle();
} while (stp.InUseThreads > 0);
}
Console.WriteLine("Enter any key to close");
Console.ReadKey();
}
private static void JobOne(SmartThreadPool obj)
{
Thread.Sleep(TimeSpan.FromSeconds(10));
Console.WriteLine(MethodBase.GetCurrentMethod());
}
private static void JobTwo(SmartThreadPool obj)
{
Thread.Sleep(TimeSpan.FromSeconds(10));
Console.WriteLine(MethodBase.GetCurrentMethod());
}
private static void StpChangeState(SmartThreadPool stp)
{
FieldInfo field = stp.GetType().GetField("_isIdleWaitHandle", BindingFlags.NonPublic | BindingFlags.Instance);
var value = (ManualResetEvent)field?.GetValue(stp);
value?.Set();
}
Metadata
Metadata
Assignees
Labels
No labels