import threading
x = 0
def up(count):
global x
for _ in range(count):
x += 1
def down(count):
global x
for _ in range(count):
x -= 1
iterations = 10
t1 = threading.Thread(target=up, args=(iterations, ))
t2 = threading.Thread(target=down, args=(iterations, ))
t1.start()
t2.start()
t1.join()
t2.join()
print(x)
Wir benutzen eine globale Variable x sowohl in der up- und der down-Funktion.
Das Ergebnis mit dem man rechnet und wahrscheinlich auch erhält ist 0.