作者mqazz1 (無法顯示)
看板Grad-ProbAsk
標題[理工] [OS] semaphore
時間Thu Dec 2 17:56:05 2010
the following program uses two semaphores, mutex and delay,
implementing a critical region.
what problem might occur?
how to fix it with still the same semaphores or other assumption?
initially, mutex=1, delay=0, count=0
=================================================================
wait(mutex);
while(!B)
{
count++;
if(count>0) signal(delay);
else signal(mutex);
wait(delay);
count--;
}
S;
if(count>0) signal(delay);
else signal(mutex);
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.228.25.55
推 christianSK:請問B 跟 S是什麼? 12/02 20:16
→ mqazz1:這個....題目沒說耶 12/02 21:17
推 christianSK:delay的初值是否要為1 12/02 22:29
推 christianSK:不然第一個人wait(delay)之後會變成-1 12/02 22:34
→ christianSK:既使後來有人signal(delay) 也還是會被卡住 12/02 22:34
→ christianSK:一點想法 12/02 22:34