comment verrouiller l'écriture sur un fil variable python

from threading import Lock, Thread
lock = Lock()
g = 0
lock.acquire()
g += 1
lock.release()
Curious Cod