I’m trying to set a real time thread priority in a c++ program and I’m getting
“pthread_setschedparam: Operation not permitted”
I observed that a “ulimit -r” prints “0”
I put “* - rtprio 99” in /etc/security/limits.conf and reboot and then “ulimit -r” prints “99”.
I’m unsure why i’m getting this “Operation not permitted” error. Same program works in Ubuntu on amd64 with the same followed steps.
Also running my program with sudo gives same error. Any help is appreciated
This is a simple code snippet that’s exhibiting the problem. Compiling with
g++ Thread.cpp -lpthread
Thread.cpp:
#include <thread>
#include <pthread.h>
#include <iostream>
#include <cstring>
class thread : public std::thread
public:
thread() {}
static void setScheduling(std::thread &th, int policy, int priority) {
sched_param sch_params;
sch_params.sched_priority = priority;
if(pthread_setschedparam(th.native_handle(), policy, &sch_params)) {
std::cerr << "Failed to set Thread scheduling : " << std::strerror(errno) << std::endl;
void example_function() {
int main() {
// create thread
std::thread example_thread(example_function);
// set scheduling of created thread
thread::setScheduling(example_thread, SCHED_RR, 2);
example_thread.join();