Answer:
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