Semaphore
Semaphore
Semaphore la bien dc bao ve gia tri cua no chi co the doc,ghi bang cac lenh dac biet p,v va lenh khoi tao. Semaphore nhi phan chi co the nhan 2 gia tri 0 va 1. Semaphore dem chi co the nhan gia tri tu nhien.
Lenh P tren Semaphore S ki hieu P(S) thuc hien nhu sau:
If S >0 then S:=S-1
Else waiting for S
Lenh V tren Semaphore S ki hieuV(S) thuc hien nhu sau:
If(exist process waiting for S)then allow one of them(waiting process) continue
Else S:=S+1
Chuong trinh ung dung Semaphore thuc hien loai tru:
Program Semaphorel
Var active: Semaphore
Procedure process 1;
Begin
While true do begin
P(active);
Critical region;
V(active);
End;
End;
Procedure process2;
Begin
InitilizeSemaphore ( active,1);
Parbegin
Process1;
Process2;
Parend
End.
Bạn đang đọc truyện trên: TruyenTop.Vip