Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

5.3 LinuxThreads POSIX 1003.1c Thread Attribute Support

5.3.1 Scheduling Attributes

This section describes the Linux POSIX 1003.1c implementation-specific support, behavior, and restrictions for thread scheduling attributes.

5.3.1.1 Start Policy

The start policy attribute is fully supported by the LinuxThreads implementation of Threads.h++ and defaults to RW_THR_START_RUNNING.

5.3.1.2 Contention Scope

In POSIX 1003.1c-compliant systems, support for contention scope is optional. Threads.h++ determines whether contention scope is supported by testing for the definition of the macro _POSIX_THREAD_PRIORITY_SCHEDULING.

LinuxThreads v0.8 does not support process-scope threads because each LinuxThread is a separate Unix process. LinuxThreads has only one scheduler for all processes.1 Therefore, all threads have a fixed contention scope of RW_THR_SYSTEM_SCOPE.

You may query the contention scope and freely set it to RW_THR_SYSTEM_SCOPE (although it is already set to that by default); but any attempt to change the scope to RW_THR_PROCESS_SCOPE produces an exception.

5.3.1.3 Scheduling Inheritance Policy

The LinuxThreads POSIX implementation of Threads.h++ fully supports the scheduling inheritance policy attribute, which defaults to RW_THR_EXPLICIT.

5.3.1.4 Concurrency Policy

LinuxThreads v0.8 does not support process-scope threads because each LinuxThread is a separate Unix process (see Section 5.4). Therefore, the concurrency policy attribute is not supported in the Linux implementation of Threads.h++. Attempts to get or set this attribute value results in exceptions.

5.3.1.5 Scheduling Policy

In POSIX 1003.1c-compliant systems, support for scheduling policy is optional. Threads.h++ determines whether scheduling policy is supported by testing for the definition of the macro _POSIX_THREAD_PRIORITY_SCHEDULING.

The LinuxThreads POSIX implementation of Threads.h++ supports all three scheduling policies as defined by the standard:

Note that LinuxThreads limits the scheduling policies SCHED_RR and SCHED_FIFO to processes with superuser privileges. Therefore, the RWSchedulingPolicy values RW_THR_PREEMPTIVE and RW_THR_TIME_SLICED_FIXED are limited to superusers as well.

Table 10 shows how Threads.h++ LinuxThreads POSIX implementation maps RWSchedulingPolicy values to the underlying POSIX 1003.1c policy values.

Table 10 -- Linux: Mapping of RWSchedulingPolicy to POSIX 1003.1c values

 
Threads.h++ RWSchedulingPolicy ValuesPOSIX 1003.1c
Scheduling Policy
RW_THR_PREEMPTIVE
SCHED_FIFO
RW_THR_TIME_SLICED_FIXED
SCHED_RR
RW_THR_TIME_SLICED_DYNAMIC
(RW_THR_OTHER may be used to set)
SCHED_OTHER

Attempts to set any other policy values will result in an RWTHROperationNotAvailable exception. None of these policies may be explicitly requested unless the process has superuser privileges.

Note that Threads.h++ has mapped two policy values to the same underlying policy, SCHED_OTHER. Calls to getSchedulingPolicy() return RW_THR_TIME_SLICED_DYNAMIC, since that value gives the most meaningful interpretation.

In order for a new thread's scheduling policy to inherit by default from the creating thread, you must change the inheritance policy's default value from RW_THR_EXPLICIT to RW_THR_INHERIT. For the default inheritance policy, Threads.h++ defines the default scheduling policy to be RW_THR_TIME_SLICED_DYNAMIC.

5.3.1.6 Scheduling Priority

In POSIX 1003.1c-compliant systems, support for the specification of thread priority is optional. Threads.h++ determines whether scheduling priority is supported by testing for the definition of macro _POSIX_THREAD_PRIORITY_SCHEDULING.

The LinuxThreads POSIX implementation does support system-scope priority scheduling. Threads.h++ uses the standard POSIX.1b (formerly POSIX.4) functions sched_get_priority_min() and sched_get_priority_max() to determine the legal range of priority values. Under this implementation, the priorities vary according to the scheduling policy, as shown in Table 11.

Table 11 -- Linux with POSIX 1003.1c: Scheduling policy priority values

 
Scheduling PolicyMinimum PriorityMaximum PriorityDefault Priority
RW_THR_PREEMPTIVE
1
99
1
RW_THR_TIME_SLICED_FIXED
1
99
1
RW_THR_TIME_SLICED_DYNAMIC
0
0
0

A new thread's priority defaults to 0, unless one of the following statements is true:

LinuxThreads v0.8 does not support process-scope threads because each LinuxThread is a separate Unix process (see Section 5.4). Therefore, process-scope priority is not supported in the Linux implementation of Threads.h++.

5.3.1.7 Scheduling Time-Slice Quantum

The LinuxThreads POSIX implementation of Threads.h++ does not support the time-slice quantum attribute. Any attempt to get or set this attribute value results in an exception.

5.3.2 Stack Attributes

In POSIX 1003.1c-compliant systems, support for user specification of stack attributes is optional. LinuxThreads supports control for a system-managed stack, and supports user-managed stacks.

The stacks for threads are allocated high in memory with the "grow on demand" flag set and spaced 2 MB apart. This means that they start off small (about 4 KB) and grow to 2 MB. However, the entire 2 MB space is reserved for the stack, which means that mapping something into a fixed address space could cause later growth of the stack to fail. On our test machine with 256 MB RAM and 256 MB swap space, we found that the maximum number of threads that could be created only using pthread_create() was about 230 threads.

The creators of LinuxThreads recommend that you not set stack attributes unless you have strong reasons for doing so, since they believe that the above stack allocation strategy is nearly optimal and that users setting the stack size may result in nonportable and less reliable programs.


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.