Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from threading import Lock
- class LockingCounter:
- def __init__(self):
- self.lock = Lock()
- self.count = 0
- def increment(self, offset):
- with self.lock:
- self.count += offset # Only one thread can execute this line at a time
Add Comment
Please, Sign In to add comment