参考了这篇文章:https://blog.csdn.net/lanyzh0909/article/details/50404664

大体的代码如下:

#include <pthread.h>
#include <sched.h> #include <stdio.h>
#include <stdlib.h>
#include <sys/sysinfo.h>
#include <sys/types.h>
#include <unistd.h> void* _thread_func(void* param){
int thread_index = *(int*)param;
int cpu_count = sysconf(_SC_NPROCESSORS_CONF);
cpu_set_t mask; // CPU核的集合
cpu_set_t get; //获取在集合中的CPU
CPU_ZERO(&mask); //置空
CPU_SET(thread_index, &mask); //设置亲和力值
//设置线程CPU亲和力
if (sched_setaffinity(0, sizeof(mask), &mask) == -1) {
printf("warning: could not set CPU %d affinity, continuing...\n", thread_index);
} else {
printf("thread %d set to cpu %d\n", thread_index, thread_index);
}
}

在高通骁龙835处理器上,始终打印如下内容:

warning: could not set CPU 7 affinity, continuing...

thread 1 set to cpu 1

thread 0 set to cpu 0

thread 3 set to cpu 3

thread 2 set to cpu 2

warning: could not set CPU 4 affinity, continuing...

thread 5 set to cpu 5

thread 6 set to cpu 6

猜测是系统故意让其中的两个核无法被设置亲缘性,原因未知。

最新文章

  1. [AngularJS] AngularJS系列(5) 中级篇之动画
  2. 修改Linux的SSH远程连接端口 技巧
  3. 有了第一台自己开发的pro,开心,明天分享最近整理逆向分析ios的一些东西
  4. android之location01
  5. [转]directsound抓取麦克风PCM数据封装类
  6. mcrypt加密与解密
  7. Hibernate与数据库分表
  8. linux查看用户登录信息-w命令
  9. Notes系统安全日志
  10. GTK+2.0学习——C指针回顾
  11. Smoke Testing(冒烟测试)
  12. ubuntu firefox上看视频,安装flash啊
  13. Beans 自动装配
  14. python 必学模块collections
  15. js 随机生成颜色值
  16. Elasticsearch集群内的原理
  17. Leetcode题库——36.有效的数独
  18. 使用 requests 配置代理服务
  19. 联想笔记本V470安装Win8.1 X64位系统,关机黑屏、电源灯亮
  20. Global Embedding 理解

热门文章

  1. Python第三周 函数详解
  2. 有个奇怪的问题,配置成/system/index,jsp页面时没有经过过滤器进行拦截,而配置成redirectAction时是可以直接跳转刀片loginJsp.action
  3. Kafka安装Kafka-Eagle可视化界面
  4. java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal报错处理
  5. 【LeetCode】234. Palindrome Linked List 解题报告(Python)
  6. 初识JavaScript变量
  7. ret2dl_resolve
  8. 数据可视化 gojs 简单使用介绍
  9. Java EE数据持久化框架 • 【第2章 MyBatis实现DML操作】
  10. Oracle数据库导入csv文件(sqlldr命令行)