Question

Consider a banking system that maintains an account balance with two functions: deposit (amount) and withdraw...

Consider a banking system that maintains an account balance with two functions: deposit (amount) and withdraw (amount). These two functions are passed the amount that is to be deposited or withdrawn from the bank account balance.
Assume that a husband and wife share a bank account. Concurrently, the husband calls withdraw ( ) function and the wife calls deposit ( ).
Describe how a race condition is possible and what might be done to prevent the race condition from occurring?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Race condition is possible if husband and wife uses the above functions [ withdraw(), deposit() ] concurrently.

For example:

If the balance =5000 and husband withdraws = 1000 ,then balance = 4000.

And balance =5000 and wife deposits =1000 , then balance=6000.

We can clearly see an inconsistency, which is not acceptable.To solve this problem we apply Peterson's Solution (to prevent race condition),

Here Flags can be used for husband and wife accessing the bank account.

int turn=0;

boolean flag=false;

User 1: Husband

do{

flag[i]=TRUE;

turn=(i+1)%2

while(flag[(i+1)%2] && turn=(i+1)%2);

withdraw();

flag[i]=FALSE;

.....(remainder section)

} while(TRUE);

This process can be repeated with User2 (Wife) wherein i will be replaced by j,i=0 or 1 and j=1 or 0.

  • The turn indicates which user is going to access the bank account next.
  • The flags make sure the events of 2 users accessing the software are mutually exclusive

Hence the Race Condition is prevented from occurring.

Add a comment
Know the answer?
Add Answer to:
Consider a banking system that maintains an account balance with two functions: deposit (amount) and withdraw...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C program to simulate deposit/withdraw activities on a banking account. (Hint: you might want...

    Write a C program to simulate deposit/withdraw activities on a banking account. (Hint: you might want to review Lab 3 slides.) (25 points)  Declare the balance as a global variable and initialize it to 600.  Write two functions, one for withdraw, the other for deposit. Both withdraw and deposit functions have one parameter, which represent the amount to withdraw or deposit. The functions deduct the balance and add to the balance one dollar at a time, respectively. Therefore,...

  • Assume we have a banking system that allows users to have joint accounts. On these joint...

    Assume we have a banking system that allows users to have joint accounts. On these joint accounts, two users may access the same account and perform withdraw and deposit concurrently. Describe how race condition can occur and in which areas of the system can it occur? Operating system course

  • Regarding commercial banking balance sheets. First, use a T-account to show how a $100 deposit affects...

    Regarding commercial banking balance sheets. First, use a T-account to show how a $100 deposit affects the balance sheet. Separate the funds into required reserves and excess reserves using a required reserve ratio of 0.1. Second, demonstrate what happens to the balance sheet when the bank loans out all of the excess reserves. Third, demonstrate what happens to the balance sheet after loaned funds are deposited in a different bank. Do not copy and paste. Please

  • Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems....

    Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems. You have to do both of your java codes based on the two provided Java codes. Create one method for depositing and one for withdrawing. The deposit method should have one parameter to indicate the amount to be deposited. You must make sure the amount to be deposited is positive. The withdraw method should have one parameter to indicate the amount to be withdrawn...

  • (C++) How do I develop a polymorphic banking program using an already existing Bank-Account hierarchy? For each account...

    (C++) How do I develop a polymorphic banking program using an already existing Bank-Account hierarchy? For each account in the vector, allow the user to specify an amount of money to withdraw from the Bank-Account using member function debit and an amount of money to deposit into the Bank-Account using member function credit. As you process each Bank-Account, determine its type. If a Bank-Account is a Savings, calculate the amount of interest owed to the Bank-Account using member function calculateInterest,...

  • In this, you will create a bank account management system according to the following specifications: BankAccount...

    In this, you will create a bank account management system according to the following specifications: BankAccount Abstract Class contains the following constructors and functions: BankAccount(name, balance): a constructor that creates a new account with a name and starting balance. getBalance(): a function that returns the balance of a specific account. deposit(amount): abstract function to be implemented in both Checking and SavingAccount classes. withdraw(amount): abstract function to be implemented in both Checking and SavingAccount classes. messageTo Client (message): used to print...

  • BANKING MANAGEMENT

    Banking System is developed in C++ to replaced manual System by a computerized system. This system allows to create a new account and Allows to deposit and withdrawal amount facilities. Account Holder ABS must record the detailed information of each account holder, such as  Type of his account (see next slides for more info)  Type of Credit card (see later slides for more info)  First name, middle name, and last name  CNIC number Address Telephone number Date of...

  • In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e.,...

    In C++ Create an inheritance hierarchy that a bank might use to represent customers’ bank accounts. All customers at this bank can deposit (i.e., credit) money into their accounts and withdraw (i.e., debit) money from their accounts. More specific types of accounts also exist. Savings accounts, for instance, earn interest on the money they hold. Checking accounts, on the other hand, charge a fee per transaction (i.e., credit or debit). Create an inheritance hierarchy containing base class Account and derived...

  • A Demand deposit B. Overdraft Account reconciliation Cash management These financial institutions, such as commercial banks,...

    A Demand deposit B. Overdraft Account reconciliation Cash management These financial institutions, such as commercial banks, savings banks, and credit unions are authorized to accept deposits This form of check also often called a banker's check payable to a third party is drawn by the bank's own funds to exchange for the amount specified in the check, plus, in most cases, a service fee. This is the general name given to an account that allows the account holder to access...

  • Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment...

    Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT