最初由Dijkstra把整型信號量定義為一個整型量
wait(S): while S≤
S∶=S
signal(S): S∶=S+
在整型信號量機制中的wait操作
type semaphore=record
value:integer;
L:list of process;
end
相應地
procedure wait(S)
var S: semaphore;
begin
S
if S
end
procedure signal(S)
var S: semaphore;
begin
S
if S
end
在記錄型信號量機制中
在兩個進程中都要包含兩個對Dmutex和Emutex的操作
process A: process B:
wait(Dmutex); wait(Emutex);
wait(Emutex); wait(Dmutex);
若進程A和B按下述次序交替執行wait操作
process A: wait(Dmutex); 於是Dmutex=
process B: wait(Emutex); 於是Emutex=
process A: wait(Emutex); 於是Emutex=
process B: wait(Dmutex); 於是Dmutex=
AND同步機制的基本思想是
Swait(S
if Si≥
for i∶=
Si∶=Si
endfor
else
place the process in the waiting queue associated with the first Si found with Si<
endif
Ssignal(S
for i∶=
Si=Si+
Remove all the process waiting in the queue associated with Si into the ready queue
endfor;
Swait(S
if Si≥t
for i∶=
Si∶=Si
endfor
else
Place the executing process in the waiting queue of the first Si with Si<ti and set its program counter to the beginning of the Swait Operation
endif
signal(S
for i∶=
Si∶=Si+di;
Remove all the process waiting in the queue associated with Si into the ready queue
endfor;
一般
(
了解更多計算機相關基礎課程視頻
[
From:http://tw.wingwit.com/Article/program/czxt/201311/24206.html