- #1
knowLittle
- 312
- 3
Homework Statement
I can't see where the problem is in the following pseudo-code.
I recall from class that the problem is based on the signal calls and wait call in pickup() and putdown()
Thank you.
Homework Equations
Code:
class Monitor R()
{
bool forks[5]; // all true
condition c[5];
void pickup(i)
{
left =i;
right=(i+1)%5;
if (forks[left])
forks[left]=F;
if (forks[right])
forks[right]=F;
while( forks[left]==F || forks[right]==F )
wait(c[i])
forks[left]=F;
forks[right]=F;
}
void putdown(i)
{
lphil=(i+4)%5;
rphil=(i+1)%5;
left=i;
right=(i+1)%5;
forks[left]=T;
forks[right]=T;
signal( c[lphil]);
signal( c[rphil] );
}
}