From 9801d8a8e43904487eb430d8d11a7517384b2403 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 5 Jan 2021 13:15:29 -0500 Subject: [PATCH] Remove ThreadStart delegate allocation from TryCreateWorkerThread (#46563) --- .../src/System/Threading/PortableThreadPool.WorkerThread.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs index c151d9f..e4b574e 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs @@ -27,6 +27,8 @@ namespace System.Threading } }); + private static readonly ThreadStart s_workerThreadStart = WorkerThreadStart; + private static void WorkerThreadStart() { Thread.CurrentThread.SetThreadPoolWorkerThreadName(); @@ -290,7 +292,7 @@ namespace System.Threading { // Thread pool threads must start in the default execution context without transferring the context, so // using UnsafeStart() instead of Start() - Thread workerThread = new Thread(WorkerThreadStart); + Thread workerThread = new Thread(s_workerThreadStart); workerThread.IsThreadPoolThread = true; workerThread.IsBackground = true; workerThread.UnsafeStart(); -- 2.7.4