Ask Question
26 January, 01:10

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.

+5
Answers (1)
  1. 26 January, 03:11
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers