count: Integer;
S: semaphore;
count:=0; S:=1; cobegin
process Pin
R1: Integer;
begin
P (S);
R1:=count;
R1:=R1+1; count:=R1; V(S);
end;
Process Pout
R2: Integer;
begin
P (S);
R2:=count;
R2:=R2-1; count:=R2; V (S);
end;
count;
end;
18.设信号量e,f1,f2; 其初值分别为 e=1,f1=0,f2=0
R1: R2: L:
P(e)
从键盘上读入 的一个数存到缓冲区B中
V(f1) Goto L L:
P(e)
从键盘上读入的一个数存到缓冲区B中
V(f2) Goto L
W1: W2:
P(f1) 将缓冲区B中的数据打印输出
V(e)
Goto L L:
P(f2) 将缓冲区B中的数据打印输出
V(e)
goto L
20.1)设置互斥信号量mutex,初值为1
P(mutex)
Enter_region
V(mutex)
2)设置同步信号量mutex,初值为m;
P(mutex)
Enter_region L: