Threads Module Platform Guide : Chapter 3 HP‑UX Technical Information : HP-UX POSIX 1003.1c Thread Attribute Support
HP-UX POSIX 1003.1c Thread Attribute Support
This section describes the HP-UX POSIX 1003.1c thread attribute support.
Scheduling Attributes
The following sections describe the HP POSIX 1003.1c implement-specific support, behavior, and restrictions for thread scheduling attributes.
Start Policy
The start policy attribute is fully supported by the Threads Module HP-UX POSIX implementation and defaults to RW_THR_START_RUNNING.
Contention Scope
In POSIX 1003.1c-compliant systems, support for contention scope is optional. The Threads Module determines whether contention scope is supported by testing for the definition of the macro _POSIX_THREAD_PRIORITY_SCHEDULING. Even if the API indicates that priority scheduling is supported, the environment may only allow one policy.
The HP implementation of POSIX 1003.1c supports both process and system scope threads.
The Threads Module HP POSIX implementation maps its RWContentionScope values to the underlying POSIX 1003.1c API as follows:
Table 4 – HP-UX: Mapping of RWContentionScope to POSIX 1003.1c values
Threads Module RWContentionScope
POSIX 1003.1c Contention Scope
RW_THR_PROCESS_SCOPE
PTHREAD_SCOPE_PROCESS
RW_THR_SYSTEM_SCOPE
PTHREAD_SCOPE_SYSTEM
Scheduling Inheritance Policy
The scheduling inheritance policy attribute is fully supported by the Threads Module HP POSIX implementation and defaults to RW_THR_INHERIT. The process must have root privileges or be a member of a group with the RTPRIO privilege in order to set a policy of RW_THR_EXPLICIT.
Concurrency Policy
The concurrency policy attribute is not supported in the Threads Module HP POSIX implementation. Attempts to get or set this attribute value will result in exceptions.
Scheduling Policy
In POSIX 1003.1c compliant systems, support for the specification of scheduling policy is optional. The Threads Module determines whether scheduling policy is supported by testing for the definition of the macro _POSIX_THREAD_PRIORITY_SCHEDULING. Even if the API indicates that priority scheduling is supported, the environment may not support all policies.
The HP implementation of the POSIX 1003.1c threads API supports all three scheduling policies as defined by the standard:
SCHED_FIFO — Specifies FIFO scheduling, where threads run until preempted by a thread of higher priority, or until blocked. Thread priorities are set by the application; the system does not dynamically change a thread’s priority.
SCHED_RR — Selects round-robin scheduling, where the highest-priority thread runs until preempted by a thread of higher priority, until some time-quantum has elapsed, or until blocked. Threads possessing the same priority value are time-sliced and scheduled in a round-robin fashion. Thread priorities are set by the application; the system does not dynamically change a thread’s priority.
SCHED_OTHER — Selects the default scheduling policy for an implementation. This policy typically uses time-slicing with dynamic adjustments to priority and/or time-slice quantum.
The Threads Module HP-UX POSIX implementation maps its RWSchedulingPolicy values to the underlying POSIX 1003.1c policy values as follows:
Table 5 – HP-UX: Mapping of RWSchedulingPolicy to POSIX 1003.1c values 
Threads Module RWSchedulingPolicy
POSIX 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 scheduling policy value will result in an RWTHROperationNotAvailable exception. None of these policies may be explicitly requested unless the process has root privileges or is a member of a group with the RTPRIO privilege.
Note that the Threads Module has mapped two policy values to the same underlying policy, SCHED_OTHER. Calls to getSchedulingPolicy() will return RW_THR_TIME_SLICED_DYNAMIC since that value gives the most meaningful interpretation.
A new thread’s scheduling policy is inherited from the creating thread by default, unless the scheduling policy attribute has been explicitly set or the inheritance policy has been changed from its default value of RW_THR_INHERIT to RW_THR_EXPLICIT. If the inheritance policy is RW_THR_EXPLICIT, the Threads Module defines the default scheduling policy to be RW_THR_TIME_SLICED_DYNAMIC.
Scheduling Priority
In POSIX 1003.1c-compliant systems, support for the specification of thread priority is optional. The Threads Module determines whether scheduling priority is supported by testing for the definition of the macro _POSIX_THREAD_PRIORITY_SCHEDULING.
The HP POSIX implementation does support priority scheduling. The Threads Module 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.
The default priorities assigned by the Threads Module and the ranges reported by these functions are as follows:
Table 6 – HP-UX with POSIX 1003.1c: Scheduling policy priority values 
Scheduling Policy
Minimum Priority
Maximum Priority
Default Priority
RW_THR_PREEMPTIVE
0
31
0
RW_THR_TIME_SLICED_FIXED
0
31
0
RW_THR_TIME_SLICED_DYNAMIC
-256
-129
N/A
A new thread’s priority value is inherited from the creating thread by default, unless the priority attribute has been explicitly set or the inheritance policy has been changed from its default value of RW_THR_INHERIT to RW_THR_EXPLICIT. If the inheritance policy is RW_THR_EXPLICIT, the Threads Module defines the default priority to be the minimum priority. HP’s implementation ignores attempts to set the priority if the scheduling policy is SCHED_OTHER (RW_THR_TIME_SLICED_DYNAMIC); threads with this scheduling policy are subject to continuous priority adjustments.
The priority of any thread may not be changed unless the process has root privileges or is a member of a group with the RTPRIO privilege.
Scheduling Time-Slice Quantum
The time-slice quantum attribute is not supported in the HP POSIX implementation of the Threads Module. Attempts to get or set this attribute value will result in exceptions.
Stack Attributes
In POSIX 1003.1c-compliant systems, support for user specification of stack attributes is optional. HP POSIX supports size control for a system-managed stack, and supports user-managed stacks.
System-Managed Stack Attributes
POSIX 1003.1c-compliant systems provide optional support for controlling the reserve size of a system-managed stack, but provide no support for controlling the commitment of physical memory and page-file space to a thread stack.
Stack Reserve Size. In POSIX 1003.1c-compliant systems, support for user specification of stack reserve size is optional. The Threads Module determines the support for stack reserve size by testing for the definition of the standard POSIX macro _POSIX_THREAD_ATTR_STACKSIZE.
The HP POSIX implementation does support the stack reserve size attribute for a system-managed stack.
If available, the Threads Module uses the following function call, sysconf(_SC_THREAD_STACK_MIN), as defined in <unistd.h>, to determine recommended minimum size for a thread stack. Otherwise, the Threads Module uses the POSIX macro, PTHREAD_STACK_MIN, to determine the recommended minimum size for a user thread stack. HP POSIX defines this value to be 4KB (the amount of stack space required to start a thread with an null function). This is the value that will be returned by the getMinStackSize() member.
If you query for the default stack reserve size, the Threads Module uses the pthread_attr_getstacksize() function to retrieve the default stack size defined by an initialized pthread_attr_t instance. Under HP-UX POSIX, the default stack size is 256KB on IA64.
The Threads Module imposes no upper limit for stack reserve size; the maximum stack size is effectively limited by available virtual memory space and page-file size. If the stack reserve size specified is too large for the available resources, an exception will be produced at the time a thread is created using the thread attribute instance with the offending reserve size value.
Stack Commit Size. The stack commit size attribute is not supported in the HP-UX POSIX implementation of the Threads Module. Attempts to get or set this attribute value will result in exceptions.
User-Managed Stack Attributes
In POSIX 1003.1c compliant systems, support for user-defined stacks is optional. The Threads Module determines the support for user-defined stacks by testing for the definition of the standard POSIX macro _POSIX_THREAD_ATTR_STACKADDR.
The Threads Module HP-UX POSIX implementation supports user-managed stacks.
If an attempt is made to set the user stack address to zero, or to set the user stack size to a value less than the minimum stack size returned by the getMinStackSize() function, a RWTHRBoundsError exception is produced.
The Threads Module imposes no upper limit for user stack size; the maximum stack size is effectively limited by the virtual memory and pagefile size available to the user.
Attempts to query for a default user-stack address value or user-stack size value will result in an RWTHROperationNotAvailable exception. These values may only be queried after they have been set.
A call to setStackReserveSize() replaces or nullifies the attribute settings produced by any previous call to setUserStack() and vice versa.