I just started with pthreads and don't know much about it. I was trying to set the priorities of pthreads using pthread_setschedprio() but it returns "EINVAL". Here is my code:
#include <pthread.h>
#include <errno.h>
void *Run(void *ptr);
class Thread {
public:
pthread_t myPthread;
void start() {
pthread_create( &myPthread, NULL, Run, (void*)this );
}
Thread() { }
virtual void run() = 0;
};
void *Run( void *ptr ) {
Thread* tmp;
tmp = (Thread*)ptr;
tmp->run();
}
class MyThread : public Thread {
public:
virtual void run() {
while (1) {
printf("Running\n");
sleep(1);
}
}
};
MyThread t1;
int main()
{
int status;
t1.start();
status= pthread_setschedprio(t1.myPthread, 300);
if(status!=0)
{
if(status==EPERM)
{
fprintf(stderr,"EPERM\n");
}
else if(status==EINVAL)
{
fprintf(stderr,"EINVAL\n");
}
else
{
fprintf(stderr,"neither EPERM nor EINVAL\n");
}
fprintf(stderr,"error %d\n",status);
errno=status;
perror("");
exit(1);
}
pthread_join( t1.myPthread, NULL);
exit(0);
}
When I try to compile it, I get EINVAL Running error 22 Invalid argument
Can anybody tell me why I get the error and how I can solve it?