Threads Module User's Guide : PART II Concurrency Packages : Chapter 3 The Threading Package : Thread Attributes : Testing For Support
Testing For Support
As discussed earlier, the specific level of support for each thread attribute varies from platform to platform. The Threading package has several mechanisms and techniques you can use for testing that level of support.
Using Feature Test Macros
Use the following feature-test macros to determine, at compile-time, whether the current environment has any support for the corresponding thread attribute:
RW_THR_HAS_CONCURRENCY_POLICY
RW_THR_HAS_CONTENTION_SCOPE
RW_THR_HAS_INHERITANCE_POLICY
RW_THR_HAS_PRIORITY
RW_THR_HAS_PROCESS_SCOPE_PRIORITY
RW_THR_HAS_SCHEDULING_POLICY
RW_THR_HAS_STACK_COMMIT_SIZE
RW_THR_HAS_STACK_RESERVE_SIZE
RW_THR_HAS_START_POLICY
RW_THR_HAS_SYSTEM_SCOPE_PRIORITY
RW_THR_HAS_TIME_SLICE_QUANTUM
RW_THR_HAS_USER_STACK
RW_THR_HAS_DUAL_PRIORITY
RW_THR_HAS_PARTIAL_STACK_COMMITMENT
If a macro is not defined, attempts to query or set the corresponding attribute always produce an exception. If the macro is defined, then the current environment has some level of support or recognition for the attribute and might allow you to get or set the attribute value.
“Get” Test Functions
Use the following functions at run-time to determine whether the current environment allows you to query the corresponding thread attributes:
canGetConcurrencyPolicy()
canGetContentionScope()
canGetInheritancePolicy()
canGetPriority()
canGetProcessScopePriority()
canGetSchedulingPolicy()
canGetStackCommitSize()
canGetStackReserveSize()
canGetStartPolicy()
canGetSystemScopePriority()
canGetTimeSliceQuantum()
canGetUserStack()
These functions follow several rules:
They return false if the corresponding attribute is not supported in the current environment or if the corresponding “get” function cannot return a legal value under current circumstances.
They return true if the corresponding attribute is supported in the current environment and the corresponding “get” function can return a legal value under current circumstances.
If the corresponding attribute value has not yet been set, then a return value of true indicates that a default value is defined and can be queried.
They return true if the corresponding attribute still has the value previously set by a call to the matching “set” function. This behavior is similar to that in the “is set” functions.
If the inheritance policy is RW_THR_INHERIT, the scheduling policy, priority, and time-slice quantum values cannot be queried for their default values. If these scheduling attributes are inherited, the “get min” and “get max” functions for these attributes will likely produce RWTHROperationNotAvailable exceptions because not enough information is available to determine the legal range of values.
Even if an attribute is supported in a particular environment, you might still be restricted from getting and setting that attribute as a consequence of other attribute values. As an example, the concurrency policy attribute might only be accessible when the contention scope is set for process-scope. Some attribute settings might also require specific security authorizations or privileges.
Once a thread has been created and is active, you can use the following RWThread or RWThreadSelf functions to test whether or not you can get the corresponding attribute value for an active thread:
canGetPriority()
canGetProcessScopePriority()
canGetSchedulingPolicy()
canGetSystemScopePriority()
canGetTimeSliceQuantum()
“Set” Test Functions
Use the following functions at run-time to determine whether the current environment allows you to set the corresponding thread attribute value:
canSetConcurrencyPolicy(RWConcurrencyPolicy)
canSetContentionScope(RWContentionScope)
canSetInheritancePolicy(RWInheritancePolicy)
canSetPriority()
canSetProcessScopePriority()
canSetSchedulingPolicy(RWSchedulingPolicy)
canSetStackCommitSize()
canSetStackReserveSize()
canSetStartPolicy(RWStartPolicy)
canSetSystemScopePriority()
canSetTimeSliceQuantum()
canSetUserStack()
These functions return one of the following values:
false if the corresponding attribute is not supported in the current environment or if the specified attribute value (if any) is not supported under current circumstances.
true if the corresponding attribute is supported in the current environment and the specified value (if any) is legal the under current circumstances.
Each of these functions that accepts a policy value produces an RWTHRBoundsError exception if the value specified as an argument is not legal policy value for that attribute. This exception can be avoided by making sure that you are using the appropriate enumerated value names for each attribute.
Once a thread has been created and is active, you can use the following RWThread or RWThreadSelf functions to test whether or not you can change the corresponding attribute value for an active thread:
canSetPriority()
canSetProcessScopePriority()
canSetSchedulingPolicy(RWSchedulingPolicy)
canSetSystemScopePriority()
canSetTimeSliceQuantum()
“Is Set” Test Functions
Use the following functions to determine whether the corresponding attribute still has the value specified by an earlier call to the matching “set” function:
isConcurrencyPolicySet()
isContentionScopeSet()
isInheritancePolicySet()
isPrioritySet()
isProcessScopePrioritySet()
isSchedulingPolicySet()
isStackCommitSizeSet()
isStackReserveSizeSet()
isStartPolicySet()
isSystemScopePrioritySet()
isTimeSliceQuantumSet()
isUserStackSet()
These functions return one of the following values:
false if the corresponding attribute value is not supported in the current environment, has not yet been set, or if a value specified earlier has been replaced with a some default value in response to a change in some related attribute.
true if the corresponding attribute is supported, has been set by a call to the matching “set” function, has not been reset with a call to the matching “reset” function, and has not been forced to a new value as the result of changes made in other attributes.