I'm learning the concept of race_condition and lock in python multithreading and I spotted this weird behavior
In the following programme
from threading import Thread
import time
value = 0
def increase():
global value
local = value
local += 1
time.sleep(0.1)
value = local
print('start value', value)
#create threads
thread1 = Thread(target=increase)
thread2 = Thread(target=increase)
#start threads
thread1.start()
thread2.start()
#join threads
thread1.join()
thread2.join()
print('end value', value)
print('end main')
while creating threads if I don't use parentheses in with function name in target as
thread1 = Thread(target=increase)
thread2 = Thread(target=increase)
I get the result
start value 0
end value 1
end main
which is normal case for race conditions but if I use parentheses as
thread1 = Thread(target=increase())
thread2 = Thread(target=increase())
I get
start value 0
end value 2
end main
which I should get after using lock on threads.. Can somebody explain?