【问题标题】:how to find the current priority of a thread in QNX如何在 QNX 中找到线程的当前优先级
【发布时间】:2013-12-31 13:12:44
【问题描述】:

谁能告诉我如何在 QNX 中找到线程的当前优先级。我使用了 pthread_getschedparam() 函数,但这不会打印预期值,因为分配的值和当前值实际上是相同的。

代码 sn-p 如下所示,l_nRetVal 返回 0 表示成功。

    pthread_t thread_id = 0;
    struct sched_param  param_test;
    int l_nPolicy = -1;
    int l_nRetVal = -1;
char l_acMyPrio[20];

   memset( &param_test, 0, sizeof(param_test) );
   memset( l_acMyPrio, 0, sizeof(l_acMyPrio) );
   thread_id = pthread_self();
   l_nRetVal = pthread_getschedparam(thread_id, &l_nPolicy, &param_test);

问候 麦迪

【问题讨论】:

标签: c pthreads qnx


【解决方案1】:

您需要查看sched_param 结构的sched_curpriority 成员才能获取线程的当前优先级。获得与您设置的值相同的值是很正常的。您可能合理地期望不同值的原因: 1. 您使用的是零星调度策略; 2.线程正在处理通过MsgReceive()及其亲属接收到的消息; 3 线程持有一个互斥体并且具有更高优先级的线程被阻塞在同一个互斥体上。

一个示例(错误处理被修剪;第二个参数为 NULL 是 QNX 扩展):

   struct sched_param  param_test;

   pthread_getschedparam(pthread_self(), NULL, &param_test);
   printf("assigned_priority=%d; current_priority=%d\n", param_test.sched_priority, param_test.sched_curpriority);

QNX 文档中的另一个示例:http://www.qnx.com/developers/docs/6.5.0_sp1/topic/com.qnx.doc.neutrino_lib_ref/s/sched_param.html

【讨论】:

    猜你喜欢
    • 2010-09-22
    • 2011-06-25
    • 2010-09-06
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 1970-01-01
    • 2012-11-17
    • 2016-06-03
    相关资源
    最近更新 更多