warming up your workspace

Mutex

Applies to: general

A mutex (mutual exclusion lock) ensures only one thread enters a critical section at a time, protecting shared data from concurrent modification. Hold it as briefly as possible, and always release it, or you risk deadlock.

with lock:
    counter += 1   # only one thread here at a time

See also: thread, race-condition