CPU 核心线程和任何软件应用程序线程有什么区别?

What is the difference between CPU core's thread and any software's application thread?

我有一个支持多线程的 Web 应用程序,我们可以在其中 运行 async 在不同线程上同时执行任务。我明白那个线程的意思。

现在假设 运行ning 应用程序所在的服务器有多个内核 CPU,并且启用了超线程。

现在,我的应用程序应该如何利用这些线程。这两者之间是否存在我所缺少的任何关系。

我从CPU的帖子中了解到

A thread is a single line of commands that are getting processed, each application has at least one thread, most have multiples. A core is the physical hardware that works on the thread. In general a processor can only work on one thread per core, CPUs with hyper threading can work on up to two threads per core. For processors with hyper threading, there are extra registers and execution units in the core so it can store the state of two threads and work on them both, normally to change threads you have to empty the registers into the cache, write that back to the main memory, then load up the cache with the new values and load up the registers, context switches hurt performance significantly.

但是当你有太多后台任务时 运行ning,它们如何只利用有限数量的核心线程(即 2 到 8 个)。

PS:我已经检查了 What is the difference between a process and a thread? 并且没有寻找过程的定义。所以它不是重复的。

如果您在程序中使用多个内核,那么 os 将调度哪些内核 运行 哪些线程,并将考虑许多因素,包括其他进程 运行ning,你的代码到底想做什么,等等。关于 async 任务,这些可能不一定 运行 在不同的线程或核心上,它们可能不是即时的任务,因此某些调度程序可能决定开始做其他事情,直到有async 任务完成的信号。根据您编写 Web 应用程序所用的语言和实现,它会有很大差异。