LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-02-2005, 06:03 AM   #1
ujjwal_rp
LQ Newbie
 
Registered: Feb 2005
Posts: 2

Rep: Reputation: 0
Thread priorities not working


Hi,

I am new to linux world.. I am creating a thread and setting the priority.

pthread_attr_t tAttr;

if (pthread_attr_init(&tAttr)==ENOMEM){
cout <<"Thread Attibute : No Memory left"<<endl;
}
if(pthread_attr_setdetachstate(&tAttr, PTHREAD_CREATE_DETACHED)!=0){
cout <<"Thread State: Error Making Detachable"<<endl;
}
struct sched_param schedParam;
pthread_t _taskId;

schedParam.sched_priority = 20;
int error = pthread_attr_setschedpolicy(&tAttr, SCHED_RR) ;
error = pthread_attr_setschedparam(&tAttr, &schedParam);
//cout << " pthread_attr_setschedparam Error = " << error << endl;
if(pthread_create(&_taskId, &tAttr, doCalculation , (void*)"Thread-20")!= 0){
cout<<" Task Creation : Resource Error , Permission Problem or Invalid Argument " <<endl;
return ;
}

//and checking the priority using following ...

int policy = 0;
if (pthread_getschedparam(_taskId, &policy, &schedParam) == 0) {
cout << "Thread sched policy = " << policy << " Prioriy = " << _schedParam.sched_priority <<endl;
}


But every time I get the output as
Thread sched policy = 0 Prioriy = 0.

Somehow priority is not getting set.. PLease help..

I am running this program on kernal 2.6.7-2.2. Fedora - 2.. Sticky bit is set

Please help. Let me know if I need to do any settings with the kernel.

Thanks and Regads
-- Ujjwal
 
Old 03-29-2007, 08:35 AM   #2
mailsteam
LQ Newbie
 
Registered: Mar 2007
Posts: 4

Rep: Reputation: 0
Hey, the problem is that, by default the priority is 0 and the maximum and minimum priority is also 0 for pc based application. It range upto 200 for rtos.. for that we have to set CONFIG_MAX_RT_PRIO.
Unless you are doing specialized real-time programming with
kernel threads, the default is fine.

here is the link frm where i got the information
http://www.kernel.org/pub/linux/kern...e8-ac4-1.patch

hope this solves your problem...all the best

Quote:
Originally Posted by ujjwal_rp
Hi,

I am new to linux world.. I am creating a thread and setting the priority.

pthread_attr_t tAttr;

if (pthread_attr_init(&tAttr)==ENOMEM){
cout <<"Thread Attibute : No Memory left"<<endl;
}
if(pthread_attr_setdetachstate(&tAttr, PTHREAD_CREATE_DETACHED)!=0){
cout <<"Thread State: Error Making Detachable"<<endl;
}
struct sched_param schedParam;
pthread_t _taskId;

schedParam.sched_priority = 20;
int error = pthread_attr_setschedpolicy(&tAttr, SCHED_RR) ;
error = pthread_attr_setschedparam(&tAttr, &schedParam);
//cout << " pthread_attr_setschedparam Error = " << error << endl;
if(pthread_create(&_taskId, &tAttr, doCalculation , (void*)"Thread-20")!= 0){
cout<<" Task Creation : Resource Error , Permission Problem or Invalid Argument " <<endl;
return ;
}

//and checking the priority using following ...

int policy = 0;
if (pthread_getschedparam(_taskId, &policy, &schedParam) == 0) {
cout << "Thread sched policy = " << policy << " Prioriy = " << _schedParam.sched_priority <<endl;
}


But every time I get the output as
Thread sched policy = 0 Prioriy = 0.

Somehow priority is not getting set.. PLease help..

I am running this program on kernal 2.6.7-2.2. Fedora - 2.. Sticky bit is set

Please help. Let me know if I need to do any settings with the kernel.

Thanks and Regads
-- Ujjwal

Last edited by mailsteam; 03-29-2007 at 08:38 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
KDE VERY slow (and other thread advice isn't working) smith847be Linux - Software 7 06-08-2004 02:21 PM
Can you change thread priorities in Linux? jmyrtle Linux - General 2 03-23-2004 05:57 AM
Yet another Sendmail thread... SMARTHOST not working mychl Linux - Networking 1 03-15-2004 08:32 AM
priorities with pthread? vprzebinda Programming 1 11-04-2003 04:19 PM
Thread Program Not Working ssuman Programming 0 04-20-2002 07:32 PM


All times are GMT -5. The time now is 10:50 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration