Anything you guys want to go over in particular? We can talk about homework problems or the midterm review posted on the class webpage if you like.
int x = 0;
void AddToX() {
for(i=0; i < 100; i++) {
x++;
}
}
void SubFromX() {
for(j=0; j < 100; j++) {
x--;
}
}
and we have one thread running AddToX() while another thread runs SubFromX(). What is the range of possible final values for x?
After the party is seated, they eat for a while, and then they leave, allowing more customers to enter. Clearly, there can never be more than N seated customers at any time, because the restaurant only has N chairs.
Each party of M customers is represented by a thread that executes the following code:
SitDown(M) // eat StandUp(M)
SitDown(M) indicates that a party of size M wants to sit down. A party will start eating as soon as SitDown returns, so SitDown must block until M seats are available. StandUp(M) indicates that a party of size M wants to stand up, freeing M chairs for waiting customers.
Define SitDown and StandUp first using monitors, then using semaphores.
Does your solution guarantee that parties of the same size are served in FIFO order? That is, if a party of 2 arrives, then later another party of 2 arrives, can you guarantee that the first party of 2 will always sit first? If not, how would you enforce this policy?