vendredi 26 juin 2020

How to increase the priority of a thread on unix like platforms

I am trying to increase the priority of an std::thread in the following way.

auto t = std::thread([]() {
    // Some heavy logic
});
int policy;
sched_param sched_p;
pthread_getschedparam(t.native_handle(), &policy, &sched_p);
sched_p.sched_priority = 20;
pthread_setschedparam(t.native_handle(), SCHED_FIFO, &sched_p);

I wish to know what is the highest priority I can assign to my std::thread named as t above. Will above code set the priority of my std::thread to highest possible value?

Can I set sched_p.sched_priority higher than 20? Is there an option better than SCHED_FIFO to use so that I give it a higher priority?

Please note that I am trying to set a thread with a higher priority within a process.

Aucun commentaire:

Enregistrer un commentaire