• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            牽著老婆滿街逛

            嚴(yán)以律己,寬以待人. 三思而后行.
            GMail/GTalk: yanglinbo#google.com;
            MSN/Email: tx7do#yahoo.com.cn;
            QQ: 3 0 3 3 9 6 9 2 0 .

            SetThreadAffinityMask設(shè)置使用多核CPU的哪個(gè)核心

            轉(zhuǎn)載自:http://cooker.javaeye.com/blog/652604

            MSDN上的描述: 
            1. SetThreadAffinityMask  
            2. The SetThreadAffinityMask function sets a processor affinity mask for the specified thread.  
            3.   
            4. DWORD_PTR SetThreadAffinityMask(  
            5.   HANDLE hThread,  
            6.   DWORD_PTR dwThreadAffinityMask  
            7. );  

            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. 



            通過(guò)調(diào)用SetThreadAffinityMask,就能為各個(gè)線程設(shè)置親緣性屏蔽: 

            C++代碼 
            1. DWORD_PTR SetThreadAffinityMask(HANDLE hThread, DWORD_PTR dwThreadAffinityMask);  


            該函數(shù)中的h T h r e a d參數(shù)用于指明要限制哪個(gè)線程, dwThreadAffinityMask用于指明該線程能夠在哪個(gè)CPU上運(yùn)行。dwThreadAffinityMask必須是進(jìn)程的親緣性屏蔽的相應(yīng)子集。返回值是線程的前一個(gè)親緣性屏蔽。 

            因此,若要將3個(gè)線程限制到CPU1、2和3上去運(yùn)行,可以這樣操作: 

            C++代碼 
            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, 0x00000002);  
            8.   
            9. SetThreadAffinityMask(hThread2, 0x00000003);  
            10.   
            11. SetThreadAffinityMask(hThread3, 0x00000004);  




            本文來(lái)自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/W511522329/archive/2010/03/06/5352597.aspx 

            C++代碼 
            1. #include "stdafx.h"  
            2. #include <windows.h>    
            3. #include <string>  
            4. #include <iostream>  
            5. void running(int seconds)  {      
            6.         Sleep(seconds*1000);  
            7.         std::cout<<"sleep for "<<seconds<<"(s)"<<std::endl;  
            8. }    
            9.   
            10. int _tmain(int argc, _TCHAR* argv[])  
            11. {  
            12.     SetThreadAffinityMask(GetCurrentThread(), 1);  
            13.     LARGE_INTEGER start, end;            
            14.     LARGE_INTEGER freq;   
            15.     //timeConsuming();  
            16.     QueryPerformanceFrequency(&freq);  
            17.     QueryPerformanceCounter(&start);//start  
            18.   
            19.   
            20.     std::cout<<"start.QuadPart = "<<start.QuadPart<<std::endl;         //output start   
            21.     running(10); //running 10 seconds  
            22.     QueryPerformanceCounter(&end); //end  
            23.     std::cout<<"end.QuadPart = "<<end.QuadPart<<std::endl;    //output end   
            24.   
            25.     std::cout<<"consume value = end.QuadPart - start.QuadPart = "<<(end.QuadPart - start.QuadPart)<<std::endl;   
            26.     std::cout<<"(consume value/(double)freq.QuadPart) Time consumed = "<<(end.QuadPart - start.QuadPart)/(double)freq.QuadPart<<"(s)"<<std::endl;  //output consumed time  
            27.     return 0;  
            28. }  





            start.QuadPart = 49102789906513 
            sleep for10(s) 
            end.QuadPart = 49127801303663 
            consume value = end.QuadPart - start.QuadPart = 25011397150 
            (consume value/(double)freq.QuadPart) Time consumed = 10.0046(s)

            posted on 2010-10-31 15:59 楊粼波 閱讀(4806) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            色婷婷综合久久久久中文| 欧美日韩精品久久免费| 国产AV影片久久久久久| 久久久精品国产Sm最大网站| 污污内射久久一区二区欧美日韩 | 久久99国产乱子伦精品免费| 精品久久久久久国产| 精品国产综合区久久久久久| 久久精品国产2020| 久久超碰97人人做人人爱| 很黄很污的网站久久mimi色| 久久综合鬼色88久久精品综合自在自线噜噜 | 国产日韩久久免费影院| 一级女性全黄久久生活片免费 | 午夜福利91久久福利| 国产成人精品久久| 99久久国产免费福利| 色天使久久综合网天天| 久久天堂电影网| 中文字幕无码免费久久| Xx性欧美肥妇精品久久久久久| 欧美激情一区二区久久久| 国产精品美女久久久| 亚洲精品无码久久久| 久久91精品国产91久久小草| 模特私拍国产精品久久| 亚洲国产精品婷婷久久| 日韩人妻无码精品久久久不卡| 人妻中文久久久久| 久久综合九色综合欧美狠狠| 久久久久久久97| 久久国产精品偷99| 久久久久久a亚洲欧洲aⅴ| 久久久久亚洲AV片无码下载蜜桃| 国产99久久久国产精免费| 久久精品国产亚洲AV无码麻豆| 亚洲欧美久久久久9999| 国内精品伊人久久久久影院对白| 精品国产一区二区三区久久久狼| 狠狠色噜噜色狠狠狠综合久久| 亚洲国产高清精品线久久|