1

I am working on thread priorities within my application. There is one realtime thread scheduled with SCHED_RR. I use pthread_setschedparam to set this policy and the priority for it. pthread_setschedparam takes the thread id as a first argument, so after creating a thread with boost::thread I can set its realtime priority.

However, another thread should have a certain nice-level, but no realtime scheduling. I can use

pid_t tid;
tid = syscall(SYS_gettid);
int ret = setpriority(PRIO_PROCESS, tid, nicelevel);

to set its nice level to ǹicelevel, but this is working only if I modify the thread function to contain the lines above. Is there a way to set the nice level from the method that creates the thread?

Thanks!

Philipp
  • 11,549
  • 8
  • 66
  • 126

1 Answers1

0

The boost::thread class exposes a public native_handle() method. In a pthreads-based implementation, this method might return a tid (it also might return a pthread_t *, depending on the meaning of handle in this particular case).

If it indeed returns a tid, using it should solve your problem. Otherwise, you'll probably have to relay the value returned by gettid() from the thread function to the global scope, as this answer suggests.

Community
  • 1
  • 1
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479