Question: please write the program in python Consider the problem of transferring some amount from one bank account to another using threads. This needs to create
Consider the problem of transferring some amount from one bank account to another using threads. This needs to create 100 threads to transfer 1 unit from account1 to account2. The following solution (program) has been proposed:



Initially, account1 has 100 units and account2 has 0 units. After 100 transfers of 1 unit, account1 should have 0 units and the account2 should have 100 units. However, this solution will result in a race condition.
a) Examine the performance of the above program by explaining its race condition state.
b) Develop a parallel solution to overcome the race condition appeared in the above program using semaphores technique.
\# Inserting delay to allow switch between threads time.sleep (0.001) self.receiver.balance = receiver_initial_balance threads = [] for i in range (100): threads.append(BankTransferthread(account1, account 2, , 1)) for thread in threads: thread.start () for thread in threads: thread.join () print (account1.balance) print(account 2 balance) Output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
