zoukankan      html  css  js  c++  java
  • SetThreadAffinityMask设置线程亲缘性

    The SetThreadAffinityMask function sets a processor affinity mask for the specified thread.

    [delphi] view plaincopyprint?
     
    1. DWORD_PTR SetThreadAffinityMask(  
    2.   HANDLE hThread,  
    3.   DWORD_PTR dwThreadAffinityMask  
    4. );  

    Parameters

    hThread
    [in] Handle to the thread whose affinity mask is to be set.

    This handle must have the THREAD_SET_INFORMATION and THREAD_QUERY_INFORMATION access rights. For more information, see Thread Security and Access Rights.

    dwThreadAffinityMask
    [in] Affinity mask for the thread.

    Windows Me/98/95:  This value must be 1.

    Return Values

    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.

    Remarks

    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,就能为各个线程设置亲缘性屏蔽:

    [delphi] view plaincopyprint?
     
    1. DWORD_PTR SetThreadAffinityMask(HANDLE hThread, DWORD_PTR dwThreadAffinityMask);  

    该函数中的h T h r e a d参数用于指明要限制哪个线程, dwThreadAffinityMask用于指明该线程能够在哪个CPU上运行。dwThreadAffinityMask必须是进程的亲缘性屏蔽的相应子集。返回值是线程的前一个亲缘性屏蔽。

    因此,若要将3个线程限制到CPU1、2和3上去运行,可以这样操作:

    [delphi] view plaincopyprint?
     
    1. //Thread 0 can only run on CPU 0.  
    2.   
    3. SetThreadAffinityMask(hThread0, 0x00000001); //第0位是1  
    4.   
    5. //Threads 1, 2, 3 run on CPUs 1, 2, 3.//第1 2 3位是1  
    6.   
    7. SetThreadAffinityMask(hThread1, 0x0000000E);  
    8.   
    9. SetThreadAffinityMask(hThread2, 0x0000000E);  
    10.   
    11. SetThreadAffinityMask(hThread3, 0x0000000E);  

    http://blog.csdn.net/yanjiaye520/article/details/7638219

  • 相关阅读:
    eclipse 批量 查询 替换
    Hibernate包及相关工具包下载地址
    逻辑运算符&& 用法解释
    主流数据库查找前几条数据的区别
    .propertie文件注释
    java.io.EOFException java.io.ObjectInputStream$PeekInputStream.readFully 错误
    数据库的名称尽量要以英文开头,如果全部输数字的话可能会出错的
    **和*的区别
    puTTY与SecureCRT的比较
    Windows下Redis的安装使用
  • 原文地址:https://www.cnblogs.com/findumars/p/4999243.html
Copyright © 2011-2022 走看看