A Bounded Resource
int AllocateEntry() {
int i;
while (!FindFreeItem(&i))
block and wait for a free slot
slot[i] = 1; /* grab free slot */
return(i);
}
void ReleaseEntry(int i) {
slot[i] = 0;
wakeup waiter, if any
}
boolean FindFreeItem(int* index) {
for (i = 0; i < TableSize; i++)
if (slot[i] == 0) return it;
return (FALSE);
}
Previous slide
Next slide
Back to first slide
View graphic version