- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
此问题基于 Jeffrey Richter 在 Microsoft Virtual Academy 中的线程类(class)。
根据我的理解,如果我将处理器关联设置为仅使用 1 个处理器,如下所示
Int32 affinity = 1;
Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)affinity;
for (int i = 0; i < 200 ; i++)
{
ThreadPool.QueueUserWorkItem(ActiveWorker);
}
ActiveWorker()
是一个 CPU 绑定(bind)函数,它只执行一些 CPU 绑定(bind)计算,大约需要 100 毫秒。当我计算创建的线程数时,它大约为 5。但根据我的理解,由于 CPU 关联设置为仅使用 1 个处理器,线程池不应创建超过 1 个线程。任何想法?在 Jeffrey 的演示中,它显示它只为整个 200 个工作项创建了 1 个线程,但是当我在我的 PC 中运行相同的示例时,我可以看到创建了 5 个线程。 (我的电脑有 2 个内核)
最佳答案
默认是每个处理器一个线程池,但该线程池中的线程数由 .Net 计算。这是 MSDN 的摘录 https://msdn.microsoft.com/en-us/library/system.threading.threadpool(v=vs.110).aspx :
There is one thread pool per process. Beginning with the .NET Framework 4, the default size of the thread pool for a process depends on several factors, such as the size of the virtual address space. A process can call the GetMaxThreads method to determine the number of threads. The number of threads in the thread pool can be changed by using the SetMaxThreads method. Each thread uses the default stack size and runs at the default priority.
关于c# - 线程池的处理器亲和性和线程创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41132596/
我只能在线找到有关将 pods 附加到基于标签的节点的文档。 有没有一种方法可以根据标签和计数将 pods 附加到节点上-那么只有带有标签y的x pods 吗? 我们的方案是,我们只想在每个节点上运行
假设一台机器上有两个处理器。线程 A 在 P1 上运行,线程 B 在 P2 上运行。 线程 A 调用 Sleep(10000); 是否有可能当线程 A 再次开始执行时,它在 P2 上运行? 如果是,谁
我想创建一个 C++11 线程,我希望它在我的第一个核心上运行。我发现 pthread_setaffinity_np 和 sched_setaffinity 可以改变线程的 CPU affinity
我正在从事计算密集型 C# 项目,该项目实现了多种算法。问题是,当我想分析我的应用程序时,特定算法所需的时间会有所不同。例如,有时运行该算法 100 次大约需要 1100 毫秒,而另一次运行 100
我想将父进程关联到一个特定的核心。在下面的代码中,变量 core 是用户提供的参数。之后,我想创建 NUM_CHILDREN 个进程,并且每个进程都以循环方式关联到其中一个核心。子进程跳出循环并执行更
我很少有与线程和进程调度相关的问题。 当我的进程进入休眠状态并唤醒时,它是否总是会被调度到之前调度的同一个 CPU 上? 当我从进程中创建一个线程时,它是否也总是在同一个 CPU 上执行?即使其他 C
我有一个服务器进程,它派生出许多子进程。服务器进程与 CPU 核心具有亲和性,但我不希望子进程继承这种亲和性(操作系统应该处理运行这些进程的位置)。有没有一种方法可以根据 cpu 亲和性解除父子进程的
尝试在 Amazon EC2 等虚拟化环境中的多核处理器上高效使用 L2 缓存时,CPU 关联性任务集是否适用? 最佳答案 不,尤其是对于较小的实例,CPU 共享量很大,您依赖于其他实例对 CPU 的
sched_setaffinity 或 pthread_attr_setaffinity_np 是否可以在 OpenMP 下设置线程关联? 相关:CPU Affinity 最佳答案 是的,命名调用将用
所以我有 4 个节点。 1是System,1是Dev,1是Qa,1是UAT。 我的亲和性如下: apiVersion: apps/v1 kind: Deployment metadata: nam
我找不到指定当附属部署使用多个副本扩展时 Kubernetes 服务行为方式的文档。 我假设有某种负载平衡。是否与服务类型有关? 此外,我希望在服务转发的请求中具有某种关联性(即,如果可能,所有具有特
我想获取有关启用了 ARR Affinity 和自动缩放的应用程序行为的详细信息? 假设我在 Azure Web App 上部署有状态 ASP.NET Web 应用。因此我启用了 ARR Affini
R 2.14.0 或更高版本包括 R package parallel它提供了对并行计算的支持。 在 类 Unix 下,此软件包提供 facility for setting CPU affinity
我想获取有关启用了 ARR Affinity 和自动缩放的应用程序行为的详细信息? 假设我在 Azure Web App 上部署有状态 ASP.NET Web 应用。因此我启用了 ARR Affini
在 Qt5 中使用线程,如何设置单个线程的 CPU affinity ? 我想指定线程可以在其下运行的可用 CPU 内核的掩码。 换句话说,Qt5相当于Posix线程的pthread_setaffin
我想通过以下方式将进程绑定(bind)到特定的核心#0(cpu 亲和性) taskset -c 0 ./run_prog 当它自己的程序在核心 #0 上运行时,操作系统可能会决定将其他后台和事件进程运
我刚刚发现了 Node.js 的worker_threads 模块,它看起来很有前途! 问题:将worker_threads与集群结合起来是否有趣/高效,或者创建的线程是否自动分布在机器的不同CPU上
我想测试在基于 64 位、2 CPU、16 核 Intel Xeon 5500 CPU 的服务器的不同物理 CPU 和不同嵌入式内存 Controller 分配和访问内存时可能发生的性能变化。 (戴尔
非常简单的问题 - 有没有办法通过 PHP 设置 CPU 亲和性?以下任何一项都可以: 通过 PHP 调用设置当前进程的亲和性。 通过 PHP 调用设置特定 PID 的亲和性。 作为最后的手段,通过命
我需要创建一个内核模块,在计算机的每个内核上启用 ARM PMU 计数器。我在设置 cpu 亲和性时遇到问题。我试过 sched_get_affinity,但显然,它只适用于用户空间进程。我的代码如下
我是一名优秀的程序员,十分优秀!