.NET 是否使用并发性或并行性或两者兼而有之?

Does .NET make use of concurrency or parallelism or both?

我知道并行和并发的区别。并发意味着处理器以非常快的速度在线程之间切换,这使得它看起来像是 运行ning 并行,因此即使使用单核处理器,您也可以同时完成事情。并行意味着每个线程 运行 在不同的核心上。

.NET 使用并行还是并发?流量是多少? cpu 是否检查线程数是否多于核心数,如果是这样,它会导致一个核心具有多个线程,从而使程序并行和并发吗?

如果我使用任务并行库会怎样?里面的名字是并列的,所以是并列还是两者兼而有之?

这个主题我不是很清楚,我一直有疑问,不确定这一切是如何运作的。

您对并发与并行的定义有些奇怪。更好的定义可能来自 How to articulate the difference between asynchronous and parallel programming

When you run something asynchronously it means it is non-blocking, you execute it without waiting for it to complete and carry on with other things. Parallelism means to run multiple things at the same time, in parallel. Parallelism works well when you can separate tasks into independent pieces of work.

您可以 运行 与 .Net 并行,最简单的方法是使用 Parallel.For.

.Net 也允许使用异步函数。 .Net API 中的大多数异步函数应映射到 OS 中的异步函数(在 windows 上,这有时称为重叠 IO)。这允许处理器在等待慢速磁盘或网络数据包时做其他事情。使用异步函数的现代方法是 async/await.

在使用并行或异步编程时,无法保证任何内容 运行 并发或以任何特定顺序进行,这取决于操作系统 and/or 框架。在大多数情况下,这将 运行 与逻辑处理器一样多的线程。我建议阅读 Parallel Processing, Concurrency, and Async Programming in .NET 以了解该主题的介绍。