Concurrency
What are the three scheduling policies shown?
- processors are generally assumed to be preemptable
- some other resources are not preemptable
i.e., mutual exclusion must be enforced between users
procedure A is
begin ...
M := M + 1; ...
end A;
procedure B is
begin ...
M := M - 1; ...
end B;
Everything works fine.
Which task executes first does not matter.
With parallel or interleaved execution, what happens?
We have a race between tasks A and B.
Even supposing the primitive memory fetch and store operations are atomic,
the outcome depends on the particular interleaving of the operations.
- Lock operation
- ``blocks'' caller until no other task is holding the lock
- the caller proceeds when it is able to get the lock
- Unlock operation
- releases the lock held by the caller
- this may allow another task that is blocked on a Lock operation
to proceed
This is the general idea. There are LOTS of variations on the
details, to be covered later in this course.
procedure A is
begin ...
Lock;
M := M + 1;
Unlock; ...
end A;
procedure B is
begin ...
Lock;
M := M - 1;
Unlock; ...
end B;
- tape drive
- printer
- modem
- region of RAM to hold program
- Counting semaphores are used for keeping track of multi-unit
resources.
- Semaphore object has a (non-negative) integer Value
- Wait operation:
wait until Semaphore.Value is positive, then decrement it
- Post operation:
increment Semaphore.Value
- These operations are atomic, meaning they are
implemented in a way that prevents them from being interleaved.
Take a look at how locks are implemented in Linux,
starting with the file spinlock.h,
in /usr/src/linux-2.2.14/include/asm-i386.
For a more detailed commentary on the more subtle parts of the
Linux spinlock implementation code click here.
-
Pi is a processor
not sharable, potentially preemptable
-
Ri is a resource
not sharable, not preemptable, serially reusable
-
Ji is a job
-
Ti is a task
-
ri is its release time
-
Di is its relative deadline
-
di is its absolute deadline
-
(ri, di] is its feasible interval
-
[r-i, r+i] is range of
ri
-
ei is (an upper bound on) its execution time
-
[e-i, e+i] is range of possible execution times
- a job may have hard or soft laxity type
- a job may be preemptable or nonpreemptable
- a job may require certain processors and resources
- all the jobs of a task have identical parameters
- periodic tasks have the following additional parameters:
-
pi is the period of a periodic task,
i.e., the minimum inter-release interval
-
ei is an upper bound on the execution times of all the jobs
in the task
-
fi is the phase, or release time of the first job
in the task
© 1998, 2003 T. P. Baker.
No part of this publication may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means without written permission.
$Id: concurrency.html,v 1.1 2003/10/17 12:34:01 baker Exp baker $ |