import threading
x = 0
m = threading.Lock()
def up(count):
global x
for _ in range(count):
m.acquire()
x += 1
m.release()
def down(count):
global x
for _ in range(count):
m.acquire()
x -= 1
m.release()
besser
import threading
x = 0
lock = threading.Lock()
def up(count):
global x
for _ in range(count):
with lock:
x += 1
def down(count):
global x
for _ in range(count):
with lock:
x -= 1