LINUX.ORG.RU

Linux threads priority problem


0

0

Dear experts, Could you, please, help me with one Linux problem you probable aware of. The problem is in setting a thread priority in Linux, unfortunately I didn't find any stable mechanism for both iPAQ and x86. Functions like setpriority(..) do not work because require root rights on mashine, all tricks I tryed with sheduller seems simply ignored in x86. The below is the exmple I played with an output for x86 and arm. If you have any ideas how this could be solved I will very appreciate it.

thanks

-V

/******************************************************************************* *************/ #include <stdio.h> #include <pthread.h>

void* Servlet (void *init) { int pid = getpid(); pthread_attr_t tattr; sched_param param; if (pthread_attr_getschedparam (&tattr, &param)) printf("Servlet%i ERROR getting scheduling params...\n"); for (int i = loops; i-->0;) { //sleep(1);

printf("Servlet%i %i :%i priority is: %i\n",*(int*)init,pid, i, param.sched_priority); } pthread_exit(NULL); } int main() { int i1=1,i2=2; pthread_t tchild; pthread_attr_t attr; sched_param schedparam; schedparam.sched_priority = 3;

pthread_attr_init(&attr); pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); // pthread_attr_setschedpolicy(&attr, SCHED_FIFO); pthread_attr_setschedparam(&attr, &schedparam); if ( pthread_create ( &tchild, &attr, Servlet, &(i1)) != 0) perror ("Could not create thread"); else pthread_detach(tchild); schedparam.sched_priority = 30; printf("%i\n\n",schedparam.sched_priority = sched_get_priority_max(SCHED_FIFO)); // pthread_attr_setschedpolicy(&attr, SCHED_RR); pthread_attr_setschedparam(&attr, &schedparam); if ( pthread_create ( &tchild, &attr, Servlet, &(i2)) != 0) perror ("Could not create thread"); else pthread_detach(tchild); /* if (sched_setscheduler(pid, SCHED_FIFO, &schp) != 0) { perror("sched_setscheduler"); return -1; } */ sleep (50);

return 0; }

/******************************************************************************* *************/

out for ARM:

Servlet1 537 :999 priority is: 32 Servlet1 537 :998 priority is: 32 Servlet1 537 :997 priority is: 32 ..... Servlet1 537 :3 priority is: 32 Servlet1 537 :2 priority is: 32 Servlet1 537 :1 priority is: 32 Servlet1 537 :0 priority is: 32 Servlet2 538 :999 priority is: 0 Servlet2 538 :998 priority is: 0 Servlet2 538 :997 priority is: 0 ..... Servlet2 538 :43 priority is: 0 Servlet2 538 :42 priority is: 0 Servlet2 538 :41 priority is: 0 Servlet2 538 :40 priority is: 0 Servlet2 538 :39 priority /******************************************************************************* *************/

out for x86:

Servlet1 429 :999 priority is: 0 Servlet1 429 :998 priority is: 0 Servlet1 429 :997 priority is: 0

..... Servlet1 429 :5 priority is: 0 Servlet1 429 :4 priority is: 0 Servlet1 429 :3 priority is: 0 Servlet1 429 :2 priority is: 0 Servlet1 429 :1 priority is: 0 Servlet1 429 :0 priority is: 0 99

Servlet2 430 :999 priority is: 0 Servlet2 430 :998 priority is: 0 Servlet2 430 :997 priority is: 0

..... Servlet2 430 :11 priority is: 0 Servlet2 430 :10 priority is: 0 Servlet2 430 :9 priority is: 0 Servlet2 430 :8 priority is: 0

anonymous

Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.