Ask Question
3 October, 23:29

Race conditions are possible in many computer systems. 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 the 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.

+4
Answers (1)
  1. 3 October, 23:49
    0
    Synchronize the bank account data in order to resolve race condition

    Explanation:

    Race condition is an unwanted situation where 2 or more then 2 process/thread perform some operation on shared data.

    In this case, two operation wants to change bank account data by performing two different operation on share data.

    In order to resolve the race condition, We only need to allow one thread at a time to alter shared data (in our case bank account). So the other thread/process will wait for the first thread to finish its task.

    From doing this, only on operation will occur on shared bank account, i. e. deposit or withdraw.

    In java, to resolve race condition we put shared data into synchronized block. Which will prevent multiple threads to perform there tasks on shared data simultaneously.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Race conditions are possible in many computer systems. Consider a banking system that maintains an account balance with two functions: ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers