Page 34 - DCAP103_Principle of operating system
P. 34
Unit 1: Operating System
The conceptual simplicity of critical regions is achieved by ignoring details of scheduling—the Notes
programmer is unaware of the sequence in which waiting processes enter critical regions and
access shared resources. This assumption is justified for processes which are so loosely connected
that simultaneous requests for the same resource rarely occur. But in most computer installations
resources are heavily used by a large group of users. In this situation, an operating system must
be able to control the scheduling of resources explicitly among competing processes. To do this,
a programmer must be able to associate an arbitrary number of event queues with a shared
variable and control the transfers of processes to and from them.
The declaration
var e: event v;
associates an event queue e with a shared variable v.
A process can leave a critical region associated with v and join the event queue e by executing
the standard procedure
await(e)
Another process can enable all processes in the event queue e to reenter their critical regions
by executing the standard procedure
cause(e)
A consumer producer relationship must now be expressed as follows:
“Consumer” “Producer”
region v do region v do
begin begin
while not B do await(e); S2;
S1; cause(e);
end end
Although less elegant than the previous notation, the present one still clearly shows that the
consumer is waiting for condition B to hold. And we can now control process scheduling to
any degree desired. To simplify explicit scheduling,
var v: shared record
available: set of R;
requests: set of P;
grant: array P of event v;
end
procedure reserve(process: P; var resource: R);
region v do
begin
while empty(available) do
begin enter(process, requests);
await(grant[process]);
LOVELY PROFESSIONAL UNIVERSITY 27