In: Computer Science
Understanding Operating Systems
It seems, in this tough economy, people are resorting to borrowing books and DVDs from the library rather than buying or renting from stores. Your library continues to thrive. You have expanded and added staff - besides you, you now have two library assistants, Peter and Jane. Peter is assigned to receive returned books, DVDs, and magazines, while Jane is in charge of lending out books and items.
As you only have a finite amount of titles to lend, you have also instituted a "Wait List" for your borrowers. If the book or DVD they're borrowing is not available, they will be put on the "waitlist". Note that for everyone's title, there could only be ONE borrower on the "waitlist" at a time.
Being new to your library, you must devise a system for Jane and Peter to follow so that:
i) Jane can check the "waitlist" when someone is borrowing
ii) Peter can update the "waitlist" when a book is returned
iii) If the book recently returned is immediately borrowed on the same day, Jane should be able to come to Peter to get the book and update the "waitlist" herself. Otherwise, Peter, at the end of the day, should put it back on the shelf.
iv) Jane and Peter can generate a report summarizing the titles borrowed and returned that day.
The key here is Jane and Peter should be synchronized in what they are going to do. Device a solution (an algorithm, pen-and-paper approach, or series of steps) to enable this new process. Software is not a solution (ie - use an SQL database or a third-party program). Apply methodologies such as test-and-set, Wait-and-signal, and semaphores to assist you in synchronization.