![]() |
|
||||
POSIX 1.c Migration Guide |
Thread Scheduling
Thread Creation Scheduling Attributes
The thread creation scheduling attributes functions and definitions have changed considerably in POSIX.1c. The following table is a comparison of the revised interfaces and their corresponding POSIX.4a versions:
Thread Creation Scheduling Interface Changes POSIX.1c POSIX.4a No equivalent No equivalent No equivalent No equivalentPOSIX.4a does not directly support the concept of thread scheduling scope. This facility is provided in POSIX.1c by the pthread_attr_setscope() and pthread_attr_getscope() functions, and the associated PTHREAD_SCOPE_SYSTEM and PTHREAD_SCOPE_PROCESS symbolic constants.
The scheduling policy values (SCHED_FIFO, SCHED_RR, SCHED_OTHER)
are unchanged.In addition to these scheduling policies, LynxOS implements non-preemptible scheduling policy SCHED_NONPREEMPT. See "Non-Preemptible Scheduling Policy" for a detailed description of this policy.
In POSIX.1c, a thread's scheduling priority attribute is set or retrieved using a sched_param structure, instead of specifying or retrieving it directly.
POSIX.4a uses the POSIX.4 Draft 9 scheduling minimum and maximum priority macros, such as PRIO_RR_MIN or PRIO_OTHER_MAX, for thread priority limits for each scheduling policy. These are replaced in POSIX.1c with the use of the POSIX.1b scheduling parameter limits retrieval functions as shown in the above table (see ISO/IEC 9945-1 1996 Section 13.3.6).
The following code fragments illustrate the differences in manipulating thread priority attributes between POSIX.4a and POSIX.1c:
POSIX.4a Code
int rv;
int prio;
pthread_attr_t attr;
:
/* Set the initial priority for the new thread */
prio = PRIO_OTHER_MIN + 10;
rv = pthread_attr_setprio(&attr, prio);
:
Equivalent POSIX.1c Code
Non-Preemptible Scheduling Policy
LynxOS implements a non-preemptible scheduling policy called SCHED_NONPREEMPT. A process running under this policy cannot be preempted by any other process until it voluntarily sleeps or blocks waiting for a semaphore or mutex object. An example of this policy is a garbage collector running with low priority and performing critical work so that it must not be interrupted. The sample code of the application is as follows:
LynxOS also defines 2 constants for the SCHED_NONPREEMPT policy designating the maximum and minimum priorities for this policy. These constants are:
These priorities can also be obtained using the sched_get_priority_max() and sched_get_priority_min() functions.
Dynamic Thread Scheduling Parameters Access
The POSIX.1c thread scheduling parameter access functions are not one-to-one replacements for their POSIX.4a counterparts, as shown in the following table:
Thread Scheduling Parameter Access Function Changes POSIX.1c POSIX.4aEach of the POSIX.1c functions combines the functionality of two corresponding POSIX.4a functions. The following code fragments illustrate the usage differences:
POSIX.4a Code
int rc;
pthread_t thread;
int prio;
:
/* Set the policy and priority of the thread */
prio = PRIO_FIFO_MIN + 10;
rc = pthread_setscheduler(thread, SCHED_FIFO, prio);
:
/* Now change only the thread's priority */
prio = pthread_getprio(thread);
rc = pthread_setprio(thread, prio + 5);
:
POSIX.1c Code
int rc;
pthread_t thread;
int policy = SCHED_FIFO;
struct sched_param param;
:
/* Set the policy and priority of the thread */
prio = sched_get_priority_min(policy);
param.sched_priority = prio + 10;
rc = pthread_setschedparam(thread, policy, ¶m);
:
/* Now change only the thread's priority */
rc = pthread_getschedparam(thread, &policy, ¶m);
param_sched_priority += 5;
rc = pthread_setschedparam(thread, policy, ¶m);
:
As in "Thread Creation Scheduling Attributes", the use of the POSIX.4 Draft 9 scheduling minimum and maximum priority macros in POSIX.4a are replaced by the POSIX.1b scheduling parameter limits retrieval functions
in POSIX.1c.
Relinquishing the Processor
The POSIX.4a pthread_yield() function has been replaced in POSIX.1c by the POSIX.1b sched_yield() function.
![]() LynuxWorks, Inc. 855 Branham Lane East San Jose, CA 95138 http://www.lynuxworks.com 1.800.255.5969 |
![]() |
![]() |
![]() |
![]() |