Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

pthreads - Setting priority with pthread_attr_setschedparam doesn't seem to change NICE value

I would like to create a thread that has lower priority than its parent.

I came up with following code with a hope that the thread has 5 for its NICE value.

      pthread_attr_t tattr;
      struct sched_param param;

      if(pthread_attr_init(&tattr) != 0)
      {
         print("Thread_Create: Error pthread_attr_init 
");
      }

      if(pthread_attr_getschedparam(&tattr, &param) != 0)
      {
         print("Thread_Create: Error pthread_attr_getschedparam 
");
      }

      if(pthread_attr_setschedpolicy(&tattr, SCHED_RR) != 0)
      {
         print("Thread_Create: Error pthread_attr_setschedpolicy 
");
      }

      param.sched_priority = 5;

      if(pthread_attr_setschedparam(&tattr, &param) != 0)
      {
         GeaLog(GeaLogLevel_Emerg, "Thread_Create: Error pthread_attr_setschedparam 
");
      }

      pthread_create(&instance->_private.thread, &tattr, Run, instance);

Now, I would like to check if it is effective. I executed ps -m -l [parent pid]

# ps -m -l 10802
F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY        TIME CMD
0 -     0 10802     1 12   -   - - 10362 -      pts/1      0:18 /usr/crank/build
0 S     0     -     - 12  80   0 -     - hrtime -          0:18 -
1 S     0     -     -  0  80   0 -     - hrtime -          0:00 -

I was expecting NI to be 5 but it's 0. Do you have any idea what I am missing?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...