CSE410 HOMEWORK #n (n=last) Due: Thursday, May 29 1. BS, p.103, Question 12. Assume that there are many processes that may invoke the reader() and writer() functions. If starvation is possible, describe an execution sequence containing starvation of some process; otherwise, argue why starvation is not possible. The solutions guarantee the basic conditions: only one writer or any number of concurrent readers may enter. Therefore, this is a valid solution to the readers/writers problem. But starvation of writers is possible. If there is an unbounded stream of readers and at least one reader is already in, then the variable read_cnt will never be zero. That means the operation V(w) will never be executed, and writers will remain blocked indefinitely. ------------------------------------------------------------------------ 2. BS, p.145, Question 9. Pb(sb) is equivalent to: L: TSB (sb,L); Vb(sb) is equivalent to: sb = 1; ------------------------------------------------------------------------ 3. BS, p.174, Question 13. With priority schedule, the following scenario will cause a deadlock: A low-priority process enters the critical section. While inside the critical section, it is preempted by a higher-priority process (that woke up from a wait or was newly created). If this process tries to enter the critical region, it will be stuck forever in the loop "while (!TS(sb))", because sb will never be set to 1. Under round robin, this problem cannot occur, since all processes get a turn periodically, and hence the first process will eventually leave the critical section and set sb to 1. ------------------------------------------------------------------------ 4. BS, p.202, Question 16. (a) One process executes: lock A1; lock A2; ... while another process executes: lock A2; lock A1; ... If this happens concurrently, the processes deadlock. (b) The processes could follow a convention to always lock the account with the smaller account number first; this would avoid any possible cycle.