标签:
The SetThreadAffinityMask function sets a processor affinity mask for the specified thread.
This handle must have the THREAD_SET_INFORMATION and THREAD_QUERY_INFORMATION access rights. For more information, see Thread Security and Access Rights.
Windows Me/98/95: This value must be 1.
If the function succeeds, the return value is the thread‘s previous affinity mask.
Windows Me/98/95: The return value is 1. To succeed, hThread must be valid and dwThreadAffinityMask must be 1.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
A thread affinity mask is a bit vector in which each bit represents the processors that a thread is allowed to run on.
A thread affinity mask must be a proper subset of the process affinity mask for the containing process of a thread. A thread is only allowed to run on the processors its process is allowed to run on.
通过调用SetThreadAffinityMask,就能为各个线程设置亲缘性屏蔽:
该函数中的h T h r e a d参数用于指明要限制哪个线程, dwThreadAffinityMask用于指明该线程能够在哪个CPU上运行。dwThreadAffinityMask必须是进程的亲缘性屏蔽的相应子集。返回值是线程的前一个亲缘性屏蔽。
因此,若要将3个线程限制到CPU1、2和3上去运行,可以这样操作:
http://blog.csdn.net/yanjiaye520/article/details/7638219
标签:
原文地址:http://www.cnblogs.com/findumars/p/4999243.html