1:利用记录型信号量解决:
Var chostick :array[0,…,4]of semaphore;
begin
repeat
wait(chopstick[i];
wait(chopstick[(i+1)mod 5]);
eat;
signal(chopstick[i]);
signal(chopstick[(i+1)mod 5]);
think;
end
2:利用AND信号机制解决哲学家进餐问题
Var chostick :array[0,…,4]of semaphore;
begin
repeat
Swait(chopstic[i],chopstick[(i+1)mod 5]);
eat;
Ssignal(chostic[i],chopstick[(i+1)mod 5]);
think;
end
参考文献:计算机操作系统....