c - Unable to change thread policy to SCHED_FIFO -


i have 2 threads, thread1 , thread2. created thread1 first , thread2. thread2 scheduled first. want schedule thread1 before thread2. changed policy of thread1 sched_fifo , policy of thread2 sched_rr. after thread2 scheduled before. declared 2 threads sched_fifo asssigned different priorities shown in below program. eventhough there no change. thought of checking policy in threads in returning 0. seems thread policy not getting changed.

please me in solving isssue.

  #include <stdio.h>   #include <pthread.h>   #include <sys/types.h>     pthread_t thread1, thread2;     void *    thread1_func (void *i)    {     struct sched_param p3;     int i1 = 0;     int policy;     = pthread_getschedparam (thread1, (int *) &policy, &p3);     printf ("in thread1 priority :%u policy: %u\n", p3.sched_priority,       policy);  }      void *   thread2_func (void *i) {    struct sched_param p3;    int i1 = 0;    int policy;    i1 = pthread_getschedparam (thread1, (int *) &policy, &p3);    printf ("in thread2 priority :%u , policy   %u\n",                   p3.sched_priority,       policy);  }   int main ()   {   struct sched_param p1, p2;     pthread_attr_t attr1, attr2;   pthread_attr_init (&attr1);   pthread_attr_init (&attr2);   pthread_attr_setinheritsched (&attr1, pthread_inherit_sched);   pthread_attr_setschedpolicy (&attr1, sched_fifo);   p1.sched_priority = 20;   pthread_attr_setschedparam (&attr1, &p1);   //pthread_attr_setschedpolicy(&attr2, sched_rr);  //pthread_attr_setschedpolicy(&attr2, sched_rr); /* tried set policy of thread1 "fifo" , thread2 "rr" make thread1 run before  

thread2 not working*/

//pthread_attr_setschedpolicy(&attr2, sched_fifo); //p2.sched_priority = 10;    //pthread_attr_setschedparam(&attr2,&p2);    pthread_create (&thread1, &attr1, (void *) thread1_func, null);    pthread_create (&thread2, null, (void *) thread2_func, null);    /*p1.sched_priority = 0;   int policy=1;   struct sched_param p4;   pthread_setschedparam(thread1,(int *)&policy,&p4);   pthread_getschedparam(thread1,&policy,&p4);   printf("the pri::::thread1 %d policy %d\n",p4.sched_priority,policy);   */    pthread_join (thread1, null);    pthread_join (thread2, null);    return 0;   } 

if you'd check result of line

  pthread_create (&thread1, &attr1, (void *) thread1_func, null); 

you'd notice call returned eperm.

from pthread_create()s documentation:

errors

the pthread_create() function shall fail if:

[...]

[eperm] caller not have appropriate privileges set required scheduling parameters or scheduling policy.


also might have @ questions along answers: getting eperm when calling pthread_create() sched_fifo thread root on linux


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -