home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
cs.rhul.ac.uk
/
www.cs.rhul.ac.uk.zip
/
www.cs.rhul.ac.uk
/
pub
/
CS375
/
attempt1.pc
next >
Wrap
Text File
|
1999-02-05
|
999b
|
47 lines
program attempt1;
var
p1requests, p2requests: boolean;
shared: integer;
process P1;
var
loop: integer;
begin
for loop := 1 to 20 do
begin
p1requests := true; (* announce intent to enter *)
while p2requests do
null; (* busy wait if other process is in critical section *)
(* enter critical section *)
shared := shared + 1;
(* leave critical section *)
p1requests :=false (* exit protocol *)
(* non-critical section *)
end
end; (* P1 *)
process P2;
var
loop: integer;
begin
for loop := 1 to 20 do
begin
p2requests := true; (* announce intent to enter *)
while p1requests do
null; (* busy wait if other process is in critical section *)
(* enter critical section *)
shared := shared + 1;
(* leave critical section *)
p2requests :=false (* exit protocol *)
(* non-critical section *)
end
end; (* P2 *)
begin
shared := 0;
cobegin
P1;
P2
coend;
writeln(shared)
end.