Guest User

Untitled

a guest
Jun 25th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.26 KB | None | 0 0
  1. from threading import Lock
  2.  
  3.  
  4. class LockingCounter:
  5. def __init__(self):
  6. self.lock = Lock()
  7. self.count = 0
  8.  
  9. def increment(self, offset):
  10. with self.lock:
  11. self.count += offset # Only one thread can execute this line at a time
Add Comment
Please, Sign In to add comment