To meet the needs of various applications, BlackBerry 10 OS provides these scheduling policies:
Each thread in the system may run using any method. Scheduling methods are effective on a per-thread basis, not on a global basis for all threads and processes on a node.
Remember that these scheduling policies apply only when two or more threads that share the same priority are READY (i.e. the threads are directly competing with each other). If a higher-priority thread becomes READY, it immediately preempts all lower-priority threads.
In the following diagram, three threads of equal priority are READY. If Thread A blocks, Thread B will run.
A thread can call pthread_attr_setschedparam() or pthread_attr_setschedpolicy() to set the scheduling parameters and policy to use for any threads that it creates.
Although a thread inherits its scheduling policy from its parent thread, the thread can call pthread_setschedparam() to request to change the algorithm and priority applied by the kernel, or pthread_setschedprio() to change just the priority. A thread can get information about its current algorithm and policy by calling pthread_getschedparam() . Both these functions take a thread ID as their first argument; you can call pthread_self() to get the calling thread's ID. For example:
struct sched_param param;
int policy, retcode;
/* Get the scheduling parameters. */
retcode = pthread_getschedparam( pthread_self(), &policy, ¶m);
if (retcode != EOK) {
printf ("pthread_getschedparam: %s.\n", strerror (retcode));
return EXIT_FAILURE;
}
printf ("The assigned priority is %d, and the current priority is %d.\n",
param.sched_priority, param.sched_curpriority);
/* Increase the priority. */
param.sched_priority++;
retcode = pthread_setschedparam( pthread_self(), policy, ¶m);
if (retcode != EOK) {
printf ("pthread_setschedparam: %s.\n", strerror (retcode));
return EXIT_FAILURE;
}
When you get the scheduling parameters, the sched_priority member of the sched_param structure is set to the assigned priority, and the sched_curpriority member is set to the priority that the thread is currently running at (which could be different because of priority inheritance).
Our libraries provide a number of ways to get and set scheduling parameters: