Question: 1. Let's say there is a program to simulate a bank with many accounts. Every account has a balance where customers can withdraw or deposit
1. Let's say there is a program to simulate a bank with many accounts. Every account has a balance where customers can withdraw or deposit money from their own accounts. Multiple threads are run by the program where each thread represents a customer making a transaction. In order to ensure the accounts are not overdrawn, the program must enforce the following constraints:
- One (only) customer can access an account at a time. When a customer withdraws money, the account balance must not go below '0'. There should be a global balance consisting of the total amount of all account balances. Even when multiple customers are accessing accounts simultaneously, the global balance must be always consistent.
We need to prepare a pseudo-code (not programming) that implements the following:
- deposits amount into the account with number accNum: void deposit (int accNum, int amount) - withdraws amount from account with number accNum. If the withdrawal would cause the account balance to go below zero, the transaction should be canceled: void withdraw (int accNum, int amount) - returns the balance of the account with the number accNum: int getBalance (int accNum) - returns global balance, which is sum of all account balances: int getGlobalBalance() - function that represents a customer thread. And args parameter must contain account number & transaction type (deposit or withdraw) for the customer: void* customer(void* args):
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
