Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this problem has to be implemented in C thanks A certain bank account is shared by n persons. That is, any of the n account

this problem has to be implemented in C
thanks image text in transcribed
A certain bank account is shared by n persons. That is, any of the n account owners should be able to deposit money to or withdraw money from the account. 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). Withdraw) will be executed by a transaction that deducts X dollars from the balance. Similarly, deponit (x) will be executed by a transaction that adds X dollars to the balance. Each of the n processes can execute either withdraw or deposit() Your monitor construct should suspend the transaction (process) invoking the withdraw function it 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. But you should always give priority to the pending withdraw operation which had been waiting longest -- if that transaction can't be completed after the most recent deposit, other pending withdraw operations should not be able to resume either. Hint: The FCFS ordering in condition_variable waiting guose assumption given below will automatically satisfy this last reguirement 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 First-Come-First-Served ordering in condition-variable waiting queues). However, this newly awakened process will have to wait until A leaves the monitor (or waits for another condition). 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 11571 A certain bank account is shared by n persons. That is, any of the n account owners should be able to deposit money to or withdraw money from the account. 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). Withdraw) will be executed by a transaction that deducts X dollars from the balance. Similarly, deponit (x) will be executed by a transaction that adds X dollars to the balance. Each of the n processes can execute either withdraw or deposit() Your monitor construct should suspend the transaction (process) invoking the withdraw function it 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. But you should always give priority to the pending withdraw operation which had been waiting longest -- if that transaction can't be completed after the most recent deposit, other pending withdraw operations should not be able to resume either. Hint: The FCFS ordering in condition_variable waiting guose assumption given below will automatically satisfy this last reguirement 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 First-Come-First-Served ordering in condition-variable waiting queues). However, this newly awakened process will have to wait until A leaves the monitor (or waits for another condition). 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 11571

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions