Remove ThreadStart delegate allocation from TryCreateWorkerThread (#46563)
authorStephen Toub <stoub@microsoft.com>
Tue, 5 Jan 2021 18:15:29 +0000 (13:15 -0500)
committerGitHub <noreply@github.com>
Tue, 5 Jan 2021 18:15:29 +0000 (13:15 -0500)
src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.cs

index c151d9f..e4b574e 100644 (file)
@@ -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();