【记录一个问题】android ndk下设置线程的亲缘性,总有两个核无法设置成功
2024-09-06 08:04:02
参考了这篇文章: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
猜测是系统故意让其中的两个核无法被设置亲缘性,原因未知。
最新文章
- [AngularJS] AngularJS系列(5) 中级篇之动画
- 修改Linux的SSH远程连接端口 技巧
- 有了第一台自己开发的pro,开心,明天分享最近整理逆向分析ios的一些东西
- android之location01
- [转]directsound抓取麦克风PCM数据封装类
- mcrypt加密与解密
- Hibernate与数据库分表
- linux查看用户登录信息-w命令
- Notes系统安全日志
- GTK+2.0学习——C指针回顾
- Smoke Testing(冒烟测试)
- ubuntu firefox上看视频,安装flash啊
- Beans 自动装配
- python 必学模块collections
- js 随机生成颜色值
- Elasticsearch集群内的原理
- Leetcode题库——36.有效的数独
- 使用 requests 配置代理服务
- 联想笔记本V470安装Win8.1 X64位系统,关机黑屏、电源灯亮
- Global Embedding 理解
热门文章
- Python第三周 函数详解
- 有个奇怪的问题,配置成/system/index,jsp页面时没有经过过滤器进行拦截,而配置成redirectAction时是可以直接跳转刀片loginJsp.action
- Kafka安装Kafka-Eagle可视化界面
- java.lang.NoClassDefFoundError: org/w3c/dom/ElementTraversal报错处理
- 【LeetCode】234. Palindrome Linked List 解题报告(Python)
- 初识JavaScript变量
- ret2dl_resolve
- 数据可视化 gojs 简单使用介绍
- Java EE数据持久化框架 • 【第2章 MyBatis实现DML操作】
- Oracle数据库导入csv文件(sqlldr命令行)