Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A certain bank account is shared by multiple persons. That is, any of the account owners should be able to deposit money to or withdraw
A certain bank account is shared by multiple persons. That is, any of the account owners should be able to deposit money to or withdraw money from the account. The exact number of account owners is not given to you (and you don't need to know it in order to solve this problem). To prevent race conditions while accessing the shared account, you will write a monitor construct. The monitor will have two procedures: withdraw (X) and deposit (X). withdraw (X) will be executed by a transaction that deducts X dollars from the balance. Similarly, deposit (X) will be executed by a transaction that adds X dollars to the balance. Each of the processes can execute either withdraw () or deposit (). Assume the balance is initialized with the value of zero. Your monitor construct should suspend the transaction (process) invoking the withdraw function if and only if there are no sufficient funds. The balance should never be negative during the execution. Multiple withdraw operation(s) may be all suspended if the balance is low. Following a deposit, suspended withdraw operation(s) must be completed subject to the availability of funds. (For example, if balance =100 and one process is suspended during the withdraw(500) transaction, a deposit of 200 dollars shouldn't enable the completion of the pending withdraw operation.) When possible, multiple suspended withdraw operation should be resumed after a deposit. You can resume the suspended withdraw processes in any order you want; however you should avoid situations where a process remains blocked even though the balance is large enough to complete its pending withdraw operation. Write the monitor construct including withdraw (X) and deposit (X) procedures to solve this problem. You will assume that standard monitor wait and monitor signal operations are available for condition variables (as discussed during the lectures). If multiple processes are suspended on a condition variable C, the execution of C.signal() by Process A will resume the process waiting the longest on C (In other words, you will assume that First-Come-First-Served ordering is implemented in condition-variable waiting queues on this operating system). However, this newly awakened process will have to wait until A leaves the monitor (or waits for another condition) [This is what we called the signal-and-continue semantics in our lectures] . There is no signal_all() or similar primitive that awakens all the processes waiting on a condition variable at once. Your solution should avoid race conditions, deadlocks and busy waiting
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started