在Android pthread_create的警告 [英] pthread_create warning on android

查看:5718
本文介绍了在Android pthread_create的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用后在pthread_create 函数我收到下一条信息:

After calling pthread_create function I receive next message:

W /的libc(26409):在pthread_create sched_setscheduler调用失败:   操作不允许

W/libc (26409): pthread_create sched_setscheduler call failed: Operation not permitted

用于创建线程的code是:

The code used to create the thread is:

pthread_attr_t threadAttr;
int ret = pthread_attr_init(&threadAttr);
//code to check ret - it's 0

size_t guard_size = 0;
pthread_attr_getguardsize(&threadAttr, &guard_size);
ret = pthread_attr_setstacksize(&threadAttr, myStackSize + guard_size);
//code to check ret - it's 0

ret = pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_DETACHED);
//code to check ret - it's 0

ret = pthread_attr_setschedpolicy(&threadAttr, SCHED_FIFO);
//code to check ret - it's 0

sched_param  schedParam;
schedParam.sched_priority = myPriority; //it's 16
ret = pthread_attr_setschedparam(&threadAttr, &schedParam);
//code to check ret - it's 0

// Create the thread
ret = pthread_create(&myHandle, &threadAttr, RunCallback, (void *)myData);
//code to check ret - it's 0
//code to check myHandle - it's > 0

// Delete attribute
pthread_attr_destroy(&threadAttr);

请注意,该消息出现在logcat中断点在RunCallback被击中了。

Please note that the message appears in logcat before breakpoint in RunCallback is hit.

你知道为什么我有这样的警告?它是安全的忽略它 - ?如果是的话,为什么

Do you know why I have this warning? Is it safe to ignore it - if yes why?

PS:code上运行的Nexus作为本地活动4设备与4.4.2操作系统版本(版本号KOT49H)

PS: code runs as native activity on Nexus 4 devices with 4.4.2 OS version(build number KOT49H).

推荐答案

在创建调度策略属性的线程,你请求一个特定的schedulinc政策应设置(的 http://man7.org/linux/man-pages/man3/pthread_attr_getschedpolicy.3.html ) 。你设置的政策,SCHED_FIFO是根据 HTTP实时政策://man7.org/linux/man-pages/man2/sched_setscheduler.2.html 。根据 HTTP的调度策略设置为一个实时策略需要CAP_SYS_NICE能力://man7.org/linux/man-pages/man7/capabilities.7.html 。因此,除非你有能力pthread_create的调用会失败。

When you create a thread with a scheduling policy attribute, you're requesting that a specific schedulinc policy should be set (http://man7.org/linux/man-pages/man3/pthread_attr_getschedpolicy.3.html). The policy you're setting, SCHED_FIFO is a real-time policy according to http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html. Setting the scheduling policy to a real-time policy requires the CAP_SYS_NICE capability according to http://man7.org/linux/man-pages/man7/capabilities.7.html. Therefore, the pthread_create call will fail unless you have that capability.

要解决这个问题,要么删除调度属性(生活在默认调度),或确保(通过启动它的根和删除所有权限,除了CAP_SYS_NICE EG)即开始与正确的功能,你的进程。

To solve the problem, either drop the scheduler attribute (and live with the default scheduling), or ensure that your process is started with the correct capabilities (e.g. by starting it as root and dropping all privileges except for CAP_SYS_NICE).

这篇关于在Android pthread_create的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆