SetThreadAffinityMask设置线程亲缘性
The SetThreadAffinityMask function sets a processor affinity mask for the specified thread.
- DWORD_PTR SetThreadAffinityMask(
- HANDLE hThread,
- DWORD_PTR dwThreadAffinityMask
- );
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,就能为各个线程设置亲缘性屏蔽:
- DWORD_PTR SetThreadAffinityMask(HANDLE hThread, DWORD_PTR dwThreadAffinityMask);
该函数中的h T h r e a d参数用于指明要限制哪个线程, dwThreadAffinityMask用于指明该线程能够在哪个CPU上运行。dwThreadAffinityMask必须是进程的亲缘性屏蔽的相应子集。返回值是线程的前一个亲缘性屏蔽。
因此,若要将3个线程限制到CPU1、2和3上去运行,可以这样操作:
- //Thread 0 can only run on CPU 0.
- SetThreadAffinityMask(hThread0, 0x00000001); //第0位是1
- //Threads 1, 2, 3 run on CPUs 1, 2, 3.//第1 2 3位是1
- SetThreadAffinityMask(hThread1, 0x0000000E);
- SetThreadAffinityMask(hThread2, 0x0000000E);
- SetThreadAffinityMask(hThread3, 0x0000000E);
http://blog.csdn.net/yanjiaye520/article/details/7638219
SetThreadAffinityMask设置线程亲缘性的更多相关文章
- Windows核心编程 第七章 线程的调度、优先级和亲缘性(下)
7.6 运用结构环境 现在应该懂得环境结构在线程调度中所起的重要作用了.环境结构使得系统能够记住线程的状态,这样,当下次线程拥有可以运行的C P U时,它就能够找到它上次中断运行的地方. 知道这样低层 ...
- Linux CPU亲缘性详解
前言 在淘宝开源自己基于nginx打造的tegine服务器的时候,有这么一项特性引起了笔者的兴趣.“自动根据CPU数目设置进程个数和绑定CPU亲缘性”.当时笔者对CPU亲缘性没有任何概念,当时作者只是 ...
- 【记录一个问题】android ndk下设置线程的亲缘性,总有两个核无法设置成功
参考了这篇文章:https://blog.csdn.net/lanyzh0909/article/details/50404664 大体的代码如下: #include <pthread.h> ...
- CPU affinity 进程和线程的亲缘性
设置Processor Affinity 作用: 1.进程和线程的亲缘性(affinity),使进程或线程在指定的CPU(核)上运行.(比如程序A,在第4个核心上运行) 2.设置进程 或者 线程, 使 ...
- Windows内核之线程的调度,优先级,亲缘性
1 调度 Windows不是实时操作系统,它是抢占式多线程操作系统.在如果全部优先级同样的情况下,CPU对线程的调度原则是每隔20m就会切换到下一个线程,依据Context中的IP和SP来接着运行上次 ...
- Windows核心编程 第七章 线程的调度、优先级和亲缘性(上)
第7章 线程的调度.优先级和亲缘性 抢占式操作系统必须使用某种算法来确定哪些线程应该在何时调度和运行多长时间.本章将要介绍Microsoft Windows 98和Windows 2000使用的一些算 ...
- KVM虚拟机cpu资源限制和vcpu亲缘性绑定
前言 KVM中添加的实例存在资源分布不均的情况,这样如果有消耗资源的实例会影响到其他实例的服务正常运行,所以给kvm做资源限制是很有必要的,下面记录一下在centos7中KVM环境下使用cgroup限 ...
- Kubernetes使用节点亲缘性将POD调度到特定节点上
节点污点可以用来让pod远离特定的节点,尽量在不修改已有pod信息的前提,通过在节点添加污点信息,来拒绝pod在某些节点上的部署. 而现在介绍一种叫做节点亲缘性,通过明确的在pod中添加的信息,来决定 ...
- Nginx设置线程数为整机内核数的俩倍!
Nginx设置线程数为整机内核数的俩倍!
随机推荐
- 为什么开发人员对于PHP语言褒贬不一
PHP 语言,作为服务器端开发的脚本语言,在网站开发方面非常有名.从1995年 Rasmus Lerdorf 创建之后,W3Techs 的调查显示在已知的服务端编程语言中,PHP 占了82%.其中不乏 ...
- JIT和程序的首次执行
由于C#源代码经过编译器编译生成的是IL代码,而IL是与CPU无关的机器语言.因此当程序运行于特定的CPU时,首先必须将IL转换成本地CPU指令,这正是JIT(Just-In-Time)编译器的任务. ...
- 在QTableView中使用各种自定义委托
QT的MVC(View/Delegate)模型十分强大,可以利用各种控件来对表格的输入进行限制,不过我以前一直没有过,这几天研究了一下,写个小例子,希望大家喜欢. 如果看不懂这个例子,请先看QT的自带 ...
- Uber上海公司被司机打上门
“Uber上周的工资没有到账,司机们都急了.”9月13日,<IT时报>记者接到Uber司机爆料,称Uber(优步)拖欠工资,客服给的解释是银行系统对接问题,但多名司机赶往Uber上海公司咨 ...
- 【C/C++】Linux下system()函数引发的错误
http://my.oschina.net/renhc/blog/54582 [C/C++]Linux下system()函数引发的错误 恋恋美食 恋恋美食 发布时间: 2012/04/21 11:3 ...
- Hadoop 6、第一个mapreduce程序 WordCount
1.程序代码 Map: import java.io.IOException; import org.apache.hadoop.io.IntWritable; import org.apache.h ...
- 【刷题 Python Tip】题目1~5
[题目1]just print a+b give you two var a and b, print the value of a+b, just do it!! print (a + b) [题目 ...
- mac系统奔溃无法启动时,如何备份重要资料
虽然说苹果系统以稳定性获得高度好评,但是作为一名程序员,还是要考虑到系统奔溃的情况. 当遇到系统奔溃,无法启动,而我们还没有备份电脑里面的重要资料,这时候不用着急.可以用下面的 方法来拯救你的苹果电脑 ...
- 使用Struts 2框架、ajax提交中文数据在后台乱码的问题
通过encodeURI()方法转码 encodeURI(url):
- CentOS 安装nload(流量统计)
yum install gcc gcc-c++ ncurses-devel wget http://www.roland-riegel.de/nload/nload-0.7.2.tar.gz tar ...