[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [rtl] pthread attribute



"Santhosh Kumar M [CEC-S]" wrote:
> 
> Hi,
> 
>         Is there a way to change the priority of a thread which is
> running. Is there any interface to change the attributes of an task
> dynamically.
> 
> Santhosh
> 
> --- [rtl] ---
> To unsubscribe:
> echo "unsubscribe rtl" | mail majordomo@rtlinux.cs.nmt.edu OR
> echo "unsubscribe rtl <Your_email>" | mail majordomo@rtlinux.cs.nmt.edu
> ----
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/~rtlinux/


Hi Santosh,

One way of changing the priority of a running thread is to use the
pthread_getschedparam and pthread_setschedparam calls.  The following
code segment could be used to change the priority of a running thread:

-----------------------------------------------------------------------------------------


  pthread_t self;
  int my_policy;
  struct sched_param my_param;

  self = pthread_self();

// Get the current thread scheduling parameters.
  if(( r_c = pthread_getschedparam(self, &my_policy, &my_param)) != 0) {
    rt_printk("pthread_getschedparam error: %d\n", r_c);
  }


// Set thread priority to the new value.
  my_param.sched_priority = NEW_PRIORITY;
  if(( r_c = pthread_setschedparam(self, my_policy, &my_param)) != 0) {
    rt_printk("pthread_setschedparam error: %d\n", r_c);
  }


-----------------------------------------------------------------------------------------


There are interface calls to change other thread attributes, but these
depend on which attribute that you want to change,

Best regards,

Steve