Page 30 - DCAP103_Principle of operating system
P. 30
Unit 1: Operating System
This notation indicates that statements S1, S2, . . . , Sn can be executed concurrently; when all Notes
of them are terminated, the following statement in the program (not shown here) is executed.
This restricted form of concurrency simplifies the understanding and verification of programs
considerably, compared to unstructured fork and join primitives. Algorithm 1 illustrates the use
of the concurrent statement to copy records from one sequential file to another.
var f, g: ¯le of T;
s, t: T; eof: Boolean;
begin
input(f, s, eof );
while not eof do
begin t := s;
cobegin
output(g, t);
input(f, s, eof );
coend
end
end
Giving video command make sure Video card is enabled.
Algorithm 1: Copying of a sequential file
The variables here are two sequential files, f and g, with records of type T; two buffers, s and
t, holding one record each; and a Boolean, eof, indicating whether or not the end of the input
file has been reached.
Input and output of single records are handled by two standard procedures. The algorithm inputs
a record, copies it from one buffer to another, outputs it, and at the same time, inputs the next
record. The copying, output, and input are repeated until the input file is empty.
Now suppose the programmer by mistake expresses the repetition as follows:
while not eof do
cobegin
t := s;
output(g, t);
input(f, s, eof );
coend
The copying, output, and input of a record can now be executed concurrently. To simplify
the argument, we will only consider cases in which these processes are arbitrarily interleaved
but not overlapped in time. The erroneous concurrent statement can then be executed in six
different ways with three possible results: (1) if copying is completed before input and output
are initiated, the correct record will be output; (2) if output is completed before copying is
LOVELY PROFESSIONAL UNIVERSITY 23