See:
Description
Packages | |
---|---|
javax.realtime |
This section describes classes that specifically manage synchronization. These classes:
NoHeapRealtimeThread
) and regular Java threads.
This specification strengthens the semantics of Java synchronized
code by mandating monitor execution eligibility control, commonly referred to as priority inversion control. The MonitorControl
class is defined as the superclass of all such execution eligibility control algorithms. Its subclasses PriorityInheritance
(required) and PriorityCeilingEmulation
(optional) avoid unbounded priority inversions, which would be unacceptable in real-time systems.
The classes in this section establish a framework for priority inversion management that applies to priority-oriented schedulers in general, and a specific set of requirements for the base priority scheduler.
The wait-free queue classes provide safe, concurrent access to data shared between instances of NoHeapRealtimeThread
and schedulable objects subject to garbage collection delays.
This list establishes the semantics and requirements that are applicable across the classes of this section. Semantics that apply to particular classes, constructors, methods, and fields will be found in the class description and the constructor, method, and field detail sections.
obj
has been assigned (either by default or via an explicit method call) the MonitorControlPolicy
mcp
, then obj
is said to be governed by mcp
.
PriorityInheritance
. The default policy can be altered by using the setMonitorControl()
method.
RealtimeSystem.getInitialMonitorControl
.
PriorityCeilingEmulation
monitor control policy is optional, since it is not widely supported by current RTOSes.
MonitorControl
subclasses must document their effects, particularly with respect to priority inversion control.
IllegalThreadStateException
is thrown. An implementation that defines a new MonitorControl
subclass must document which (if any) schedulers do not support this policy.
The following list defines the main terms and establishes the general semantics and requirements that apply to threads and schedulable objects managed by the base priority scheduler when they synchronize on objects governed by monitor control policies defined in this section.
t
is initially the priority that t
has when it is created. The base priority is updated (immediately) as an effect of invoking any of the following methods:
pparams.setPriority(prio)
t
is a schedulable object with pparams
as its SchedulingParameters,
where pparams
is an instance of PriorityParameters
; the new base priority is prio
t.setSchedulingParameters(pparams)
t
is a schedulable object and pparams
is an instance of PriorityParameters
; the new base priority is pparams.getPriority()
t.setPriority(prio)
t
is a schedulable object, the new base priority is prio
. If it is a Java thread, the new base priority is the lesser of prio
, and the maximum priority for t
's thread group.t
does not hold any locks, its active priority is the same as its base priority. In such a situation modification of the priority of t
through an invocation of any of the above priority-setting methods for t
causes t
to be placed at the tail of its relevant queue (ready, blocked on a particular object, etc.) at its new priority.
t
holds one or more locks, then t
has a set of priority sources. The active priority for t
at any point in time is the maximum of the priorities associated with all of these sources. The priority sources resulting from the monitor control policies defined in this section, and their associated priorities for a schedulable object t
, are as follows:
t
itselft
Note: This may have been changed (either synchronously or asynchronously) while t
has been holding its lock(s). t
and governed by a PriorityCeilingEmulation
policyceil
such that ceil
is the ceiling for a PriorityCeilingEmulation
policy governing an object locked by t.
This value is also referred to as the ceiling priority for t
.t
and governed by a PriorityInheritance
policyt
and governed by a PriorityCeilingEmulation
policy.PriorityCeilingEmulation
lock to behave like a PriorityInheritance
lock, helps avoid unbounded priority inversions that could otherwise occur in the presence of nested synchronizations involving a mix of PriorityCeilingEmulation
and PriorityInheritance
policies.
t
either leaves t
's active priority unchanged, or increases it. If t
's active priority is unchanged, then t
's status in its relevant queue (e.g. blocked waiting for some object) is not affected. If t
's active priority is increased, then t
is placed at the tail of the relevant queue at its new active priority level.
t
either leaves t
's active priority unchanged, or decreases it. If t
's active priority is unchanged, then t
's status in its relevant queue (e.g. blocked waiting for some object) is not affected. If t
's active priority is decreased and t
is either ready or running, then t
must be placed at the head of the ready queue at its new active priority level, if the implementation is supporting PriorityCeilingEmulation
. If the implementation is not supporting PriorityCeilingEmulation
then t
should be placed at the head of the ready queue at its new active priority (Note the "should": this behavior is optional.) If PriorityCeilingEmulation
is not supported, the implementation must document the queue placement effect. If t
's active priority is decreased and t
is blocked, then t
is placed in the corresponding queue at its new active priority level. Its position in the queue is implementation defined, but placement at the tail is recommended.The above rules have the following consequences:
t
's priority sources from 4.b are added and removed synchronously; i.e., they are established based on t
's entering or leaving synchronized code. However, priority sources from 4.a, 4.c and 4.d may be added and removed asynchronously, as an effect of actions by other threads or schedulable objects.obj.wait()
it releases the lock on obj
and hence relinquishes the priority source(s) based on obj
's monitor control policy. The thread or schedulable object will be queued at a new active priority that reflects the loss of these priority sources.
PriorityParameters
object may be associated with multiple schedulable objects), a given base priority may be the active priority for some but not all of its associated schedulable objects.
It is a consequence of other rules that, when a thread or schedulable object t
attempts to synchronize on an object obj
governed by a PriorityCeilingEmulation
policy with ceiling ceil
, then t
's active priority may exceed ceil
but t
's base priority must not. In contrast, once t
has successfully synchronized on obj
then t
's base priority may also exceed obj
's monitor control policy's ceiling. Note that t
's base priority and/or obj
's monitor control policy may have been dynamically modified.
The following list establishes the semantics and requirements that apply to threads or schedulable objects managed by a scheduler other than the base priority scheduler when they synchronize on objects with monitor control policies defined in this section.
Scheduler
subclass must document which (if any) monitor control policies the new scheduler does not support.
PriorityInheritance
instance. It must supply documentation for the behavior of the new scheduler with priority inheritance (and, if it is supported, priority ceiling emulation protocol) equivalent to the semantics for the default priority scheduler found in the previous section.
Java's rules for synchronized
code provide a means
for mutual exclusion but do not prevent unbounded priority inversions
and thus are insufficient for real-time applications. This
specification strengthens the semantics for synchronized
code by mandating priority inversion control, in particular by
furnishing classes for priority inheritance and priority ceiling
emulation. Priority inheritance is more widely implemented in
real-time operating systems and thus is required
and is the initial default mechanism in this specification.
Since the same object may be accessed from synchronized code by both a NoHeapRealtimeThread
and an arbitrary thread or schedulable object, unwanted dependencies may result. To avoid this problem, this specification provides three wait-free queue classes as an alternative means for safe, concurrent data accesses without priority inversion.
.