I am trying to set priority of threads using poco threads and threadpool API. but when I try running program and try to see the set priority using htop it is always showing 20. Also the the OS min and MAX priority is being printed as 0 in terminal as as I have added couts to print the same. I am running program on ubuntu 16 based Linux. Any help or suggestion will be appreciated.
Essentially I want to increase the priority of few threads. I was using poco TaskManager but it is not providing the mechanism to set priority. so I am trying to use Poco threads to do the same but it is also not helping.
#include <Poco/Runnable.h>
#include <Poco/Thread.h>
#include <Poco/ThreadPool.h>
#include <Poco/ThreadTarget.h>
#include <Poco/RunnableAdapter.h>
#include <string>
#include <iostream>
class Foo : public Poco::Runnable
{
public:
virtual void run()
{
std::cout << " run() start" << std::endl;
Poco::Thread *t = Poco::Thread::current();
int pmax = t->getMaxOSPriority();
int pmin = t->getMinOSPriority();
cout << "T1 priority " << t->getOSPriority() << " min " << pmin << " max " << pmax << endl;
t->setOSPriority(pmax);
cout << "T1 priority " << t->getOSPriority() << endl;
cout << "T1 priority " << t->getPriority() << endl;
Poco::Thread::sleep(200);
std::cout << " run() end" << std::endl;
}
};
int main()
{
// setting priority Using threadpool
Poco::ThreadPool::defaultPool().addCapacity(16);
Foo foo;
Poco::ThreadPool::defaultPool().startWithPriority(Poco::Thread::Priority::PRIO_LOW, foo);
Poco::ThreadPool::defaultPool().joinAll();
// setting priority Using thread
Poco::Thread thread;
thread.start(foo);
thread.join();
return 0;
}
Aucun commentaire:
Enregistrer un commentaire