在使用监视器的 Dining Philosophers 实现中,为什么 putdown() 操作调用 test() 操作两次?
procedure take_chopsticks(i)
{
DOWN(me);
pflag[i] := HUNGRY;
test[i];
UP(me);
DOWN(s[i]) }
void test(i)
{
if ( pflag[i] == HUNGRY
&& pflag[i-1] != EAT
&& pflag[i+1] != EAT)
then
{
pflag[i] := EAT;
UP(s[i])
}
}
void drop_chopsticks(int i)
{
DOWN(me);
test(i-1);
test(i+1);
UP(me);
}