EECS 111: System Software, Spring 2023, Homework 2 Name: ________________________________ Student ID: ________________________________ • All homework will be written by hand. No computer-typed homework will be accepted. • You should scan the homework, convert it to pdf and submit it to Canvas system. • Emailed homework will not be accepted. • You can find the answer to the following questions in the lecture, in the book, or you might need to search for it online. 1. Suppose that a university wants to show off how politically correct it is by applying the U.S. Supreme Court’s ‘‘Separate but equal is inherently unequal’’ doctrine to gender as well as race, ending its long-standing practice of gender-segregated bathrooms on cam- pus. However, as a concession to tradition, it decrees that when a woman is in a bath- room, other women may enter, but no men, and vice versa. A sign with a sliding marker on the door of each bathroom indicates which of three possible states it is currently in: • Empty • Women present • Men present In pseudocode, write the following procedures: woman_wants_to_enter, man_wants_to_enter, woman_leaves, man_leaves. You may use whatever counters and synchronization techniques you like. 2. Servers can be designed to limit the number of open connections. For example, a server may wish to have only N socket connections at any point in time. As soon as N connections are made, the server will not accept another incoming connection until an existing connection is released. Explain how semaphores can be used by a server to limit the number of concurrent connections. 3. What is the difference between compare_and_swap() and test_and_set() instructions in a multiprocessor environment. Show how to implement the wait() and signal() semaphore operations in multiprocessor environments using the compare_and_swap() and test_and_set() instructions. The solution should exhibit minimal busy waiting. 4. Design an algorithm for a bounded-buffer monitor in which the buffers (portions) are embedded within the monitor itself. 5. Discuss the tradeoff between fairness and throughput of operations in the readers–writers problem. Propose a method for solving the readers–writers problem without causing starvation. 6. How does the signal() operation associated with monitors differ from the corresponding operation defined for semaphores? 7. Race conditions are possible in many computer systems. Consider a banking system with two methods: deposit (amount) and withdraw (amount). These two methods are passed the amount that is to be deposited or withdrawn from a bank account. Assume that a husband and wife share a bank account and that concurrently the husband calls the withdraw() method and the wife calls deposit(). Describe how a race condition is possible and what might be done to prevent the race condition from occurring. -1-