Hardware Reference
In-Depth Information
τ
τ D
W
R
int x = 1;
int y = 2;
x = 4;
y = 8;
plot(x,y);
Figure 2.9
Two tasks sharing a buffer with two variables.
plot(x,y)
τ
R
D
x=4
y=8
τ W
R
R
t
(1,2)
(4,2)
(4,8)
Figure 2.10
Example of schedule creating data inconsistency.
To better understand why mutual exclusion is important for guaranteeing data consis-
tency, consider the application illustrated in Figure 2.9, where two tasks cooperate to
track a moving object: task τ W gets the object coordinates from a sensor and writes
them into a shared buffer R , containing two variables ( x, y ); task τ D reads the vari-
ables from the buffer and plots a point on the screen to display the object trajectory.
If the access to the buffer is not mutually exclusive, task τ W (having lower priority
than τ D ) may be preempted while updating the variables, so leaving the buffer in an
inconsistent state. The situation is illustrated in Figure 2.10, where, at time t , the ( x, y )
variables have values (1,2). If τ W
is preempted after updating x and before updating
y , τ D
will display the object in (4,2), which is neither the old nor the new position.
To ensure a correct access to exclusive resources, operating systems provide a synchro-
nization mechanism (e.g., semaphores) that can be used to create critical sections of
code. In the following, when we say that two or more tasks have resource constraints,
we mean that they share resources that are accessed through a synchronization mech-
anism.
Search WWH ::




Custom Search