如何在Windows中的私有托管池中设置线程优先级?

问题描述 投票:1回答:1

我正在按照here给出的例子。虽然我能够成功创建线程,但这些线程对所有进程都具有默认关联。

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

c++ windows multithreading threadpool
1个回答
1
投票

好吧,我假设你想要亲和力。 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); 
© www.soinside.com 2019 - 2024. All rights reserved.