我正在按照给出的示例 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/