简体   繁体   English

“Hello world”应用程序在.NET4.0中使用4个线程,但在.NET2.0中使用3个线程

[英]“Hello world” application uses 4 threads in .NET4.0, but 3 in .NET2.0

When running the most basic "Hello, World!" 当运行最基本的“Hello,World!”时 application compiled for .NET2.0 you should see 3 threads (Main, GC and Finalizer). 为.NET2.0编译的应用程序,您应该看到3个线程(Main,GC和Finalizer)。 However, with a .NET4.0 build that number goes up to 4 with the same basic application. 但是,对于.NET4.0版本,使用相同的基本应用程序,该数字最多可达4。 Does anyone know what the extra thread is for? 有谁知道额外的线程是什么?

The thread pool keeps idle thread(s) by default since .NET4 (as MSDN points it ). 默认情况下,线程池保持空闲线程, 因为.NET4 (因为MSDN指向它 )。 I cant find how their number is specified (although you can change it with SetMinThreads), it probably isnt. 我无法找到他们的数字是如何指定的(尽管你可以用SetMinThreads改变它),它可能不是。

This dotNetPerls article suggests that it depends also on the number of cores on the machine (which makes sense). 这篇dotNetPerls文章表明它还取决于机器上的核心数量(这是有道理的)。

You could test on your machine/specific program to print ThreadPool.GetMinThreads() with both CLRs. 您可以在您的机器/特定程序上测试,以使用两个CLR打印ThreadPool.GetMinThreads()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM