Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

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


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


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);


this piece of code is written in the init_module()

pthread_attr_t attr;
struct sched_param sched_param;
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, 11:50 PM   #2
LQ 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-29-2008, 12:32 AM   #3
Registered: Dec 2008
Location: Chandigarh, India
Distribution: Red Hat 9
Posts: 67

Original Poster
Rep: Reputation: 15

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.


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

All times are GMT -5. The time now is 02:42 AM.

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