**:
#include
#include
#include
#include
#include
#include
void * thr_fun(void *arg)
if (policy == sched_fifo)
else if (policy == sched_other)
else if (policy == sched_rr)
printf("param:%d/n", param.sched_priority);
long long i;
while (1)
pthread_exit(null);
}int main(void)
//if (inher == pthread_explicit_sched)
else if (inher == pthread_inherit_sched)
//設定繼承的排程策略
//必需設定inher的屬性為 pthread_explicit_sched,否則設定執行緒的優先順序會被忽略
ret = pthread_attr_setinheritsched(&attr, inher);
if (ret!=0)
policy = sched_fifo;//在ubuntu9.10上需要root許可權
//設定執行緒排程策略
ret = pthread_attr_setschedpolicy(&attr, policy);
if (ret!=0)
param.sched_priority = 3;
//設定排程引數
ret = pthread_attr_setschedparam(&attr, ¶m);
if (ret!=0)
//建立執行緒
ret = pthread_create(&tid, &attr, thr_fun, null);
if (ret!=0)
while (1)
pthread_join(tid, null);
pthread_exit(null);
}
Linux執行緒優先順序設定
本程式會讓系統失去i o響應,不建議去執行!include include include include include include void thr fun void arg if policy sched fifo else if policy sched other else if po...
linux執行緒的優先順序設定
linux並不是實時作業系統,把下面的 執行一遍就能夠理解了,有很詳細的注釋。cpp view plain copy print?include include include include include include void thr fun void arg if policy sched...
linux下設定執行緒優先順序
在linux下我們可以通過 int pthread create pthread t thread,const pthread attr t attr,void start routine void void arg 來建立執行緒,但是如何設定執行緒的優先順序呢?在討論這個問題的時候,我們先要確定當...