In Java I know we can set priority's of threads, example:
Thread t1 = new Thread();
t1.setPriority(Thread.MIN_PRIORITY);
I'm looking at the various ways of handling this in C++ and the main differences between Thread priority in Java and C++, does thread priority work in a similar way giving a thread more access to resources over a lower thread? Or in C++ does it just refer to the amount of CPU that thread has access to?
Would this Java implementation be viable in C++?
class thrun implements Runnable
{
Thread t;
boolean runn = true;
thrun(String st,int p)
{
t = new Thread(this,st);
t.setPriority(p);
t.start();
}
publicvoid run()
{
System.out.println("Thread name : " + t.getName());
System.out.println("Thread Priority : " + t.getPriority());
}
}
class priority
{
publicstaticvoid main(String args[])
{
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
thrun t1 = new thrun("Thread1",Thread.NORM_PRIORITY + 2);
thrun t2 = new thrun("Thread2",Thread.NORM_PRIORITY - 2);
System.out.println("Main Thread : " + Thread.currentThread());
System.out.println("Main Thread Priority : " + Thread.currentThread().getPriority());
}
}