Ask Question

Race conditions are possible in many computer systems. Consider a banking system with two methods: deposit (amount) and withdraw (amount). These two methods are passed the amount that is to be deposited or withdrawn from a bank account. Assume that a husband and wife share a bank account and that concurrently the husband calls the withdraw () method and the wife calls deposit (). Describe how a race condition is possible and what might be done to prevent the race condition from occurring.

+2
Answers (1)
  1. 31 July, 08:40
    0
    Race Condition is possible if husband and wife both have concurrent functionality.

    Explanation:

    For eg. if Balance = 3000 and husband withdraws = 1000 then remaining balance is = 2000.

    One the other hand if balance is 3000 and wife deposits = 1000 then remaining balance is 4000

    we can see that there is inconsistency that is not acceptable.

    To solve the problem mostly we are using Peterson's Algorithm

    Account can be used for husband and wife,

    int flag = 0

    boolean account

    1 : Husband

    do{

    account[i] = TRUE;

    flag = (i+1) %2

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

    withdraw ();

    account[i] = FALSE

    (remainder)

    } While (TRUE);

    This process can be repeat with (Wife) where i will be replaced by j, i=0 or 1 and j = 1 or 0

    flag identify which is going to access the bank account account make sire that 2 users are mutually exclusive

    Proved the race condition is prevented
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Race conditions are possible in many computer systems. Consider a banking system with two methods: deposit (amount) and withdraw (amount). ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers