Skip to content

Commit

Permalink
Fixed ThreadCount for WindowsThreadPool on Clr+Mono
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardo-vp committed Jun 2, 2023
1 parent 3646176 commit 0651298
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ internal static void InitializeForThreadPoolThread()
{
WindowsThreadPool.InitializeForThreadPoolThread();
}
else
{
InitializeForThreadPoolThreadPortableCore();
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -203,8 +199,6 @@ public static long CompletedWorkItemCount
}
}

private static void InitializeForThreadPoolThreadPortableCore() { }

private static RegisteredWaitHandle RegisterWaitForSingleObject(
WaitHandle waitObject,
WaitOrTimerCallback callBack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static ThreadPoolCallbackWrapper Enter()
if (!currentThread.IsThreadPoolThread)
{
currentThread.IsThreadPoolThread = true;
// when using the Windows Threadpool, this is needed to increment the ThreadCount
ThreadPool.InitializeForThreadPoolThread();
}
return new ThreadPoolCallbackWrapper
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public void MetricsTest()
Assert.True(totalWorkCountToQueue >= 1);
waitForWorkStart = true;
scheduleWork();
int threadCountLowerBound = UsePortableThreadPool ? totalWorkCountToQueue : 0;
int threadCountLowerBound = UsePortableThreadPool ? totalWorkCountToQueue : 1;
Assert.True(ThreadPool.ThreadCount >= threadCountLowerBound);
int runningWorkItemCount = queuedWorkCount;
Expand Down

0 comments on commit 0651298

Please sign in to comment.