LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Regarding giving the priority to a thread (https://www.linuxquestions.org/questions/programming-9/regarding-giving-the-priority-to-a-thread-693550/)

navderm 12-28-2008 09:29 PM

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.

paulsm4 12-28-2008 10:50 PM

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 ...

navderm 12-28-2008 11:32 PM

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.


All times are GMT -5. The time now is 03:40 PM.