Do you have a question? Post it now! No Registration Necessary
Subject
- Posted on
- Robert Scott
January 14, 2008, 7:42 pm

My application needs a main thread for the user interface and a real-time thread
to monitor some analog inputs. So this is what I did, based on the article
found here:
http://www.ibm.com/developerworks/linux/library/l-ipc2lin1.html
//..in the main thread:
pthread_attr_t threadAttr;
struct sched_param param;
pthread_attr_init(&threadAttr);
pthread_attr_setstacksize(&threadAttr, 32768);
pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_DETACHED);
pthread_create(&worker,&threadAttr,&worker_function,NULL);
pthread_attr_destroy(&threadAttr);
//..Then, in the worker_function:
struct sched_param param;
int policy;
pthread_t thread_id = pthread_self();
pthread_getschedparam(thread_id, &policy, ¶m);
printf("existing policy=%1d, priority=%1d\r\n",
policy,param.sched_priority);
//..This yields policy=SCHED_OTHER, priority=0..
policy = SCHED_RR;
param.sched_priority = 90;
pthread_setschedparam(thread_id, policy, ¶m);
- - - - - - - - - - - - - - - - - - - - -
This all seems to work fine. But I don't know why the article suggested 90 for
the priority. And I don't know why SCHED_RR (which I assume stands for
round-robin) is the proper policy for my worker thread. I don't need
exceptionally high priority for my worker thread. I just need it to be
sllightly higher than my main thread. So should I do a getschedparam on the
main thread and just add 1 for the worker priority?
Robert Scott
Ypsilanti, Michigan
to monitor some analog inputs. So this is what I did, based on the article
found here:
http://www.ibm.com/developerworks/linux/library/l-ipc2lin1.html
//..in the main thread:
pthread_attr_t threadAttr;
struct sched_param param;
pthread_attr_init(&threadAttr);
pthread_attr_setstacksize(&threadAttr, 32768);
pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_DETACHED);
pthread_create(&worker,&threadAttr,&worker_function,NULL);
pthread_attr_destroy(&threadAttr);
//..Then, in the worker_function:
struct sched_param param;
int policy;
pthread_t thread_id = pthread_self();
pthread_getschedparam(thread_id, &policy, ¶m);
printf("existing policy=%1d, priority=%1d\r\n",
policy,param.sched_priority);
//..This yields policy=SCHED_OTHER, priority=0..
policy = SCHED_RR;
param.sched_priority = 90;
pthread_setschedparam(thread_id, policy, ¶m);
- - - - - - - - - - - - - - - - - - - - -
This all seems to work fine. But I don't know why the article suggested 90 for
the priority. And I don't know why SCHED_RR (which I assume stands for
round-robin) is the proper policy for my worker thread. I don't need
exceptionally high priority for my worker thread. I just need it to be
sllightly higher than my main thread. So should I do a getschedparam on the
main thread and just add 1 for the worker priority?
Robert Scott
Ypsilanti, Michigan

Re: Launching a real-time thread with higher priority than main

You can setup realtime priorities from 1 to 99. 1 would be enough if there
are no other realtime processes (but consider the interrupts, see below)

You must change it to one of the realtime scheduler policies (SCHED_RR or
SCHED_FIFO). That's all. SCHED_OTHER would keep it at the non realtime
scheduler.

If you only have one realtime thread/process is doesn't matter what priority
it has. If there are more than one of them you must select their priority
very carefully. BTW: Interrupts in RT Preempt are running at realtime
priority 50 as default.
JB
Site Timeline
- » auto mounting usb with uClinux
- — Next thread in » Embedded Linux
-
- » Program equivalent of "mount" command
- — Previous thread in » Embedded Linux
-
- » Crosscompiling for ARM: reloc type R_ARM_ABS32 is not supported for PIC - ...
- — Newest thread in » Embedded Linux
-
- » Martwa płyta PC retro - od czego zacząć?
- — The site's Newest Thread. Posted in » Electronics (Polish)
-