SocketAsyncEngine.Unix: name socket event thread (#35471)
authorTom Deseyn <tom.deseyn@gmail.com>
Mon, 27 Apr 2020 19:59:56 +0000 (21:59 +0200)
committerGitHub <noreply@github.com>
Mon, 27 Apr 2020 19:59:56 +0000 (15:59 -0400)
* SocketAsyncEngine.Unix: name socket event thread

This makes it more easy to identify the thread amongst
the other threads in the application.

* PR feedback

* Make System.Threading.Thread Reference specific to Unix

src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj
src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketAsyncEngine.Unix.cs

index 6c3c50e..0b6a149 100644 (file)
     <Reference Include="System.Threading.Overlapped" />
     <Reference Include="System.Threading.ThreadPool" />
   </ItemGroup>
+  <ItemGroup Condition="'$(TargetsUnix)' == 'true'">
+    <Reference Include="System.Threading.Thread" />
+  </ItemGroup>
 </Project>
index 732fd08..96a95c4 100644 (file)
@@ -277,19 +277,15 @@ namespace System.Net.Sockets
                     throw new InternalException(err);
                 }
 
-                //
-                // Start the event loop on its own thread.
-                //
                 bool suppressFlow = !ExecutionContext.IsFlowSuppressed();
                 try
                 {
                     if (suppressFlow) ExecutionContext.SuppressFlow();
-                    Task.Factory.StartNew(
-                        s => ((SocketAsyncEngine)s!).EventLoop(),
-                        this,
-                        CancellationToken.None,
-                        TaskCreationOptions.LongRunning,
-                        TaskScheduler.Default);
+
+                    Thread thread = new Thread(s => ((SocketAsyncEngine)s!).EventLoop());
+                    thread.IsBackground = true;
+                    thread.Name = ".NET Sockets";
+                    thread.Start(this);
                 }
                 finally
                 {