我使用pthread_create()在我的Linux应用程序中创建了一个线程。我想让这个线程以非常低的优先级运行,因为在同一个应用程序中有一些实时线程在运行。下面是线程函数本身中的代码:
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
/* Trying to set lowest priority possible for this thread */
我很难理解setscheduler函数中的sched_priority角色。
我使用的是linux 2.4.X,文档中写道:
Valid priorities for SCHED_OTHER is 0, Valid priorities for SCHED_RR\FIFO are 1...MAX_USER_RT_PRIO-1
但是,我记得rt进程的优先级是0-99,SCHED_OTHER的优先级是100-139,所以...我错过了什么?struct sched_param中的sched_priority指的是什么?
我正在为嵌入式linux设备实现电源管理支持。要求是在系统中没有剩余的东西可以运行,并且下一个计时器事件足够远的时候,执行系统挂起到内存。我打算基于现有的内核enter_state()函数
最初,我计划从cpu_idle()函数(空闲内核线程)调用我的代码,因为它是在系统中没有什么可运行的时候运行的。但是我遇到了一个问题,enter_state()最终调用了schedule()函数,然后我得到一条错误消息:"bad: scheduling from the idle线程!“
因此,我得出结论,我必须创建自己的内核线程,但具有最低的静态优先级。我的问题是如何做到这一点?
另一个问题是:在
在图书馆pthread.h是pthread_rwlock_t FIFO吗?
在下面的示例中,我们有多个线程。假设每个线程都保证按顺序运行。
// Thread 1 - does a write lock
pthread_rwlock_wrlock(&lock);
// Thread 2 - does a read but has to wait for 1
pthread_rwlock_rdlock(&lock);
// Thread 3 - does a read but has to wait for 1
pthread_rwlock_rdlock(&lock)
在用于线程调度的POSIX api中,我们可以让不同的线程采用不同的调度策略。 示例: pthread_attr_setschedpolicy (&attr, SCHED_FIFO); // set policy first in first out
pthread_create(&tid1,&attr,runner,NULL); // create thread with first in first out
pthread_attr_setschedpolicy (&attr, SCHED_RR); // set policy round robin