This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: HW #2 SYNCHRONIZATION Choose three of the five problems and provide a synchronization solution using Semaphores. Where appropriate we have given some stub-functions, you do not have to use the same code in your solution. As a solution, you may submit either pseudo-code, real code, or nat- ural language. If you submit a natural language solution, it must explicitly state where the P’s and V’s of your mutexes and sempahores should go. If you code your solution using JNachos, and it runs fine, this may not indicate your solution is perfect as pre-emption can only happen at specific times, unlike a real machine, where pre-emption can happen at any time. (1) Oliver Twist: There are N orphans at an orphanage. During meal time there is a communal pot full of gruel (food), that the orphans help themselves to. The pot has an integer maximum capacity of M , and a current amount S , initially the pot is full. The orphans run a loop where they fill their bowls and then eat (decreasing the contents of the communal pot) ( S- 1). If the pot becomes empty ( S == 0), then orphans must wait for the cook to come along and refill the pot ( S = M ). 1: procedure Orphan code (UnSynchronized) 2: while true do 3: getServing(); 4: eat(); 5: end while 6: end procedure 7: 1: procedure Cook code (UnSynchronized) 2: while true do 3: fillPot(); 4: end while 5: end procedure Synchronized constraints: Constraints: The cook can only invoke fillPot(), if the pot is empty....
View Full Document