打电话后pthread_create
函数我收到下一条消息:
W/libc (26409): pthread_create sched_setscheduler 调用失败:
不允许操作
用于创建线程的代码是:
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);
请注意,在 RunCallback 中的断点被命中之前,该消息会出现在 logcat 中。
你知道为什么我会收到这个警告吗?忽略它是否安全 - 如果是,为什么?
PS:代码在操作系统版本为 4.4.2(内部版本号 KOT49H)的 Nexus 4 设备上作为本机活动运行。
你打电话时pthread_attr_setschedpolicy
,您请求设置特定的调度策略(http://man7.org/linux/man-pages/man3/pthread_attr_setschedpolicy.3.html http://man7.org/linux/man-pages/man3/pthread_attr_setschedpolicy.3.html)。您制定的政策,SCHED_FIFO
,是根据实时策略http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html http://man7.org/linux/man-pages/man2/sched_setscheduler.2.html。将调度策略设置为实时策略需要CAP_SYS_NICE
能力根据http://man7.org/linux/man-pages/man7/capability.7.html http://man7.org/linux/man-pages/man7/capabilities.7.html。因此,pthread_attr_setschedpolicy
除非你有这个能力,否则调用将会失败。
要解决这个问题,要么删除调度程序属性(并使用默认调度),要么确保您的进程以正确的功能启动(例如,以 root 身份启动并删除除CAP_SYS_NICE
).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)