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()
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.
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".
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 07:45 PM.|