The original code was
import time, threading
balance = 0
def change_it(n):
global balance
balance = balance + n
balance = balance - n
def run_thread(n):
for i in range(2000000):
change_it(n)
t1 = threading.Thread(target=run_thread, args=(5,))
t2 = threading.Thread(target=run_thread, args=(8,))
t1.start()
t2.start()
t1.join()
t2.join()
print(balance)
Which gave random results cause the threads were influencing each other But when I tried
t1 = threading.Thread(target=run_thread(5))
t2 = threading.Thread(target=run_thread(8))
it worked properly every time. Why are they different?