LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-28-2008, 09:29 PM   #1
navderm
Member
 
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Rep: Reputation: 15
Regarding giving the priority to a thread


Hello

I request you guys to please give me the difference between these two pieces of codes which are used to assign priority to a thread

1.

this piece of code is written in the thread itself

{
struct sched_param p;
p.sched_priority = 1;
pthread_setschedparam (pthread_self(), SCHED_FIFO, &p);
pthread_make_periodic_np(pthread_self(), gethrtime(), 80000000);
}


2.

this piece of code is written in the init_module()

{
pthread_attr_t attr;
struct sched_param sched_param;
pthread_attr_init(&attr);
sched_param_sched_priority = 1;
pthread_attr_setschedparam (&attr, &sched_param);
pthread_create (&thread, &attr, thread_fn, (void *) 0);
}


what is the difference between these two codes, which one is better and why? And if they are actually different, where should each one be used?

Waiting for a prompt and lucid reply.

Thank you.
 
Old 12-28-2008, 10:50 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
You aren't trying to avoid using mutexes, are you ;-)?

If I see code that spends more time playing with thread attributes (which, 99 times out of 100, you probably don't need to mess with anyway) than getting the basic algorithms right... that's a definite "yellow flag".

IMHO ...
 
Old 12-28-2008, 11:32 PM   #3
navderm
Member
 
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Original Poster
Rep: Reputation: 15
Hi

I have to work with mutexes. but currently i am trying to do all the work in single thread. this will give me a general overview of how my algorithm should be. I am sure that in RTlinux if you are working with single thread you probably wont need to use the priority setups but since i have to use multiple threads later to the same algorithm i was trying to figure out how to do it.
This is when i got the problem.

The algorithm of the controller that i am developing currently is very simple. it has to be made more robust but i need my first program to work before i can continue with that.
 
  


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
How should i map Windows thread priority macros to Linux? patyogesh Linux - Newbie 3 11-12-2008 05:20 AM
How do I obtain root thread priority (on non-root user)? paintballer1016 Linux - General 11 07-24-2007 02:02 PM
Priority of Linux process/thread scanner Linux - Newbie 1 07-07-2006 12:49 AM
thread priority tornatom Programming 0 08-22-2005 01:00 PM
Giving users printing priority amfoster Linux - General 0 10-05-2004 06:35 PM


All times are GMT -5. The time now is 09:59 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