80 likes | 210 Views
IPC and IPS Problems. Jehan-François Pâris jfparis@uh.edu. Problem I: RPC. Consider the following C function void trans (int *from, int *to, double amount){ *from -= amount; *to += amount; } //trans. Problem I: RPC. What would happen if we execute trans (&bal, & bal, 5000.00); using
E N D
IPC and IPS Problems Jehan-François Pârisjfparis@uh.edu
Problem I: RPC • Consider the following C function • void trans (int *from, int *to, double amount){ *from -= amount; *to += amount;} //trans
Problem I: RPC • What would happen if we executetrans (&bal, & bal, 5000.00);using • regular procedure calls ? • RPC calls?
Problem I : RPC • We will have problems with RPC!
Problem II: mutual exclusion • What is wrong with the following solution to the mutual exclusion problem? //Global arrayshared int wait[2] = {0, 1}; void enter(int pid) { // pid must be 0 or 1while (wait[pid]); } // enter_region void leave_region(int pid) { wait[pid] = 1;wait[1 – pid] = 0; } // leave_region
Problem 3: monitors • A pizza oven has enough space inside for ten pizzas and a small opening through which a single cook can put a pizza in the oven and remove it when it is ready. Add the required pseudocode to the following monitor to ensure the smooth operation of the oven. (8×2 pts) • Class pizza_oven { private int npizzas; // pizzas in oven private condition not_empty; private condition not_full; • public void synchronized put_a_pizza() { __________________________________________ __________________________________________ put_a_pizza_in_the_oven(); __________________________________________ __________________________________________ } // put_a_pizza() • public void synchronized remove_a_pizza() { __________________________________________ __________________________________________ take_a_pizza_from_the_oven(); __________________________________________ __________________________________________ } // remove_a_pizza() • oven() { npizzas = 0; } // constructor} // Class oven
Problem 3: monitors • Class pizza_oven { private int npizzas; // pizzas in oven private condition not_empty; private condition not_full; • public void synchronized put_a_pizza() { __________________________________________ __________________________________________ put_a_pizza_in_the_oven(); __________________________________________ __________________________________________ } // put_a_pizza() • public void synchronized remove_a_pizza() { __________________________________________ __________________________________________ take_a_pizza_from_the_oven(); __________________________________________ __________________________________________ } // remove_a_pizza() • oven() { npizzas = 0; } // constructor} // Class oven
Problem 3: monitors • Pizan() { npizzas = 0; } // constructor} // Class oven