Race conditions are possible in many computer systems Consid

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.

Solution

Here balance is the shared variable between two processes.
Race conditions occur when both process try to use the shared variable balance.

Suppose balance is 5000
If husband withdraw 1000
Balance is 4000.
In mean time wife deposit one thousand it must be 5000. But if they are executed in a interleaved fashion database will go to inconsistent state.
Example:
P1 reads balance 5000
P2 reads balance 5000

P1 withdraw 1000 balance=4000
P2 deposits 1000 balance=6000

Which is inconsistent. This is called race condition.

Race conditions are possible in many computer systems. Consider a banking system with two methods: deposit(amount) and withdraw(amount). These two methods are p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site