c++ - 如何在 Windows 中的私有(private)管理池中设置线程优先级?

标签 c++ windows multithreading threadpool

我正在按照给出的示例 here .虽然我能够成功创建线程,但这些线程对所有进程具有默认亲和性。

如何设置亲和性?有人可以提供一个示例,说明如何将 SetThreadAffinityMask 与上面链接中给出的示例一起使用吗?

最佳答案

好吧,我假设你想要亲和性。 SetThreadAffinityMask 的第二个参数是一个位掩码,表示允许线程在哪些处理器上运行。这些位在相应的处理器上设置为 1。例如:

// binary 01, so it allows this thread to run on CPU 0
SetThreadAffinityMask(hThread, 0x01); 
// binary 10, so it allows this thread to run on CPU 1
SetThreadAffinityMask(hThread, 0x02); 
// binary 11, so it allows this thread to run on CPU 0 or CPU 1
SetThreadAffinityMask(hThread, 0x03); 

关于c++ - 如何在 Windows 中的私有(private)管理池中设置线程优先级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8543936/

相关文章:

c++ - 使用模板作为返回值。如何处理无效返回?

c - 如何在 Windows 上用 C 语言发出哔声?

c# - 关闭 Windows 资源管理器的特定实例

c++ - 这里需要内存屏障 "*pEnd_ = v; __sync_synchronize ();++pEnd_;"吗?

windows - 在 Delphi 下终止应用程序时线程未终止

c++ - 虚拟基类是可行的和/或有用的功能吗

c++ - 使用 DELETE 来节省内存,有人可以证明

windows - 如何使用 ftp 将变量传递到批处理文件的 %0 部分?

java - 不丢弃数据包的距离 vector 线程

c++ - C++ 中的模板函数