多线程编程指南

thr_setprio 语法

thr_setprio(3C) 可用来将当前进程内 tid 所指定线程的优先级更改为 newprio 所指定的优先级。对于 POSIX 线程,请参见pthread_setschedparam 语法

#include <thread.h>



int thr_setprio(thread_t tid, int newprio)

缺省情况下,线程是基于范围从 0(最不重要)到 127(最重要)的固定优先级来调度的。

thread_t tid;

int ret;

int newprio = 20;



/* suspended thread creation */

ret = thr_create(NULL, NULL, func, arg, THR_SUSPENDED, &tid);



/* set the new priority of suspended child thread */

ret = thr_setprio(tid, newprio);



/* suspended child thread starts executing with new priority */

ret = thr_continue(tid);