staticvoid set_thread_policy(pthread_attr_t*attr,int policy) { int rs =pthread_attr_setschedpolicy(attr,policy); assert(rs==0);
get_thread_policy(attr); }
int main(void) { pthread_attr_t attr; struct sched_param sched; int rs;
rs =pthread_attr_init(&attr); assert(rs==0);
int policy = get_thread_policy(&attr); printf("Show current configuration of priority\n");
show_thread_priority(&attr,policy); printf("show SCHED_FIFO of priority\n");
show_thread_priority(&attr,SCHED_FIFO); printf("show SCHED_RR of priority\n");
show_thread_priority(&attr,SCHED_RR); printf("show priority of current thread\n"); int priority = get_thread_priority(&attr);
policy=SCHED_OTHER
Show current configuration of priority
max_priority=0
min_priority=0
show SCHED_FIFO of priority
max_priority=99
min_priority=1
show SCHED_RR of priority
max_priority=99
min_priority=1
show priority of current thread
priority=0Set thread policy set SCHED_FIFO policy
policy= SCHED_FIFO set SCHED_RR policy
policy= SCHED_RRRestore current policy
policy=SCHED_OTHER