【问题标题】:How to set thread priority in privately managed pools in Windows?如何在 Windows 的私有管理池中设置线程优先级?
【发布时间】:2012-01-22 13:21:21
【问题描述】:

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

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

【问题讨论】:

  • 那么你想要亲和力还是优先级?

标签: c++ windows multithreading threadpool


【解决方案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); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多