Scheduling Time-Slice Quantum
The time-slice quantum attribute is used to define the maximum amount of time that a thread is allowed to execute before forcibly preempting it to allow another thread to execute. A time-slice quantum is typically associated with a scheduling policy of RW_THR_TIME_SLICED_FIXED.
Using the feature test macro. The feature test macro for scheduling time-slice quantum is RW_THR_HAS_TIME_SLICE_QUANTUM. If this macro is not defined, attempts to query or set the time-slice quantum attribute always produce an exception. If it is defined, then the current environment has some level of support or recognition for time-slice quantum and might allow you to get or set this attribute. A time-slice quantum is defined in terms of milliseconds using an unsigned long value.
Member functions. The RWThreadAttribute member functions that are used to manipulate the scheduling time-slice quantum include:
canGetTimeSliceQuantum() — Indicates whether the time-slice quantum is supported in the current environment and whether
getTimeSliceQuantum() can currently return a legal value.
isTimeSliceQuantumSet() — Indicates whether the time-slice quantum value is the value that was previously set by a call to
setTimeSliceQuantum(unsigned long).
getTimeSliceQuantum() — Returns the default time-slice quantum value if the attribute value has not yet been defined. Otherwise, it returns the value specified in the last call to
setTimeSliceQuantum(unsigned long). If the current environment or circumstances do not allow interrogation of the time-slice quantum, then attempts to use this function result in exceptions.
canSetTimeSliceQuantum() — Indicates whether the time-slice quantum attribute is supported and can be set in the current environment.
setTimeSliceQuantum(unsigned long) — Sets the time-slice quantum attribute to the value passed as an argument. If the current environment does not support the adjustments to the time-slice quantum or if the specified attribute value is outside the legal range, then the function produces an exception.
resetTimeSliceQuantum() — Restores the time-slice quantum attribute to its default value. The default value can vary according to the current value of other attributes, such as priority.
getMinTimeSliceQuantum() — Returns the minimum priority value supported by the current contention scope and scheduling policy.
getMaxTimeSliceQuantum() — Returns the maximum priority value supported by the current contention scope and scheduling policy.
Changing the inheritance or scheduling policy attributes. Adjustment of the time-slice quantum is not supported by many platforms and can be safely ignored because this attribute assumes an appropriate default value. Changing the inheritance or scheduling policy attributes, either directly or as the result of a change in contention scope, can cause a previous time-slice quantum setting to be discarded and can affect the availability and allowable range of values for this attribute, as shown in the next table.
Inheritance Policy | Scheduling Policy | Time-Slice Quantum |
---|
N/A | N/A | Not Available |
Inherit | [Inherited] | [Inherited] (if available) |
Explicit | Preemptive (if available) | Not Available |
Fixed Time-Slicing (if available) | Policy-Dependent Range (if available) |
Dynamic Time-Slicing(if available) | Not Available |
NOTE: The specific dependencies and validation requirements for the time-slice quantum attribute are unique to each environment, and can be found in the appropriate section of the Platform Guide supplement.
Inheriting the time-slice quantum. The time-slice quantum value can be inherited from the creating thread if the inheritance policy attribute is defined as RW_THR_INHERIT. If the inheritance attribute is RW_THR_EXPLICIT, the Threading package chooses a default policy appropriate for the current settings and environment. Setting the time-slice quantum attribute value when the current inheritance policy is RW_THR_INHERIT forces the inheritance policy attribute to be changed to RW_THR_EXPLICIT.
Using the time-slice quantum. The time-slice quantum specified by an RWThreadAttribute can only be used at thread creation. To manipulate the time-slice quantum for an active thread, use the following RWThread and RWThreadSelf member functions:
canGetTimeSliceQuantum() getTimeSliceQuantum() canSetTimeSliceQuantum() setTimeSliceQuantum(unsigned long) getMinTimeSliceQuantum() getMaxTimeSliceQuantum() Exceptions. In addition to throwing the same exceptions as their RWThreadAttribute counterparts, an RWTHRThreadNotActive exception is thrown if you attempt to query or set the time-slice quantum on a threaded runnable that does not possess an active thread.