简体   繁体   English

SetThreadAffinityMask 设置的处理器亲和性是否也适用于子线程?

[英]Does a processor affinity set by SetThreadAffinityMask also apply to children threads?

I have an application that makes use of many threads, one of them being more time critical than the others.我有一个使用许多线程的应用程序,其中一个线程比其他线程更需要时间。 I have already tried using priority, but have found that Windows doesn't always honor the priority to the extent I would like and sometimes allows lessor priority threads to block my critical thread for long periods (50+ milliseconds).我已经尝试过使用优先级,但发现 Windows 并不总是按照我想要的程度尊重优先级,有时允许次优先级线程长时间(50+ 毫秒)阻塞我的关键线程。 To resolve this, I'm thinking of setting a processor affinity for each thread to limit the non-critical ones such that they can't use some cores (say cores #1 and #2) and the critical thread will always have those cores (#1 and #2) available.为了解决这个问题,我正在考虑为每个线程设置一个处理器亲和性,以限制非关键线程,这样它们就不能使用某些核心(比如核心 #1 和 #2),而关键线程将始终拥有这些核心(#1 和#2)可用。

My question is, if I set a processor affinity mask to my entry-point thread via SetThreadAffinityMask() , do subsequent threads created by this initial thread inherit the affinity mask?我的问题是,如果我通过SetThreadAffinityMask()为我的入口点线程设置处理器关联掩码,那么由该初始线程创建的后续线程是否继承关联掩码? Or do I need to manually set the affinity each and every time I spawn a thread throughout the system?还是每次在整个系统中生成线程时都需要手动设置亲和性?

I can confirm the thread affinity is NOT inherited when creating a thread using std::thread with VS2015 on Windows 10.我可以确认在 Windows 10 上使用带有 VS2015 的 std::thread 创建线程时不会继承线程亲和性。

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

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