Guest User

Untitled

a guest
Nov 13th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import threading
  2. class Reader(threading.Thread):
  3. def run(self):
  4. while True:
  5. with RW.LW:
  6. pass
  7.  
  8. with RW.LR:
  9. RW.read_count += 1
  10.  
  11. readData(RW.data)
  12.  
  13. with RW.LR:
  14. RW.read_count -= 1
  15. RW.LR.notify()
  16.  
  17. doMoreWork()
  18.  
  19. class Writer(threading.Thread):
  20. def run(self):
  21. while True:
  22. with RW.LW:
  23. waiting = True
  24. while waiting:
  25. with RW.LR:
  26. if RW.read_count == 0:
  27. updateData(Rw.data)
  28. waiting = False
  29. else:
  30. # use wait/notify to avoid busy waiting
  31. while RW.read_count != 0:
  32. RW.LR.wait()
  33. doOtherWork()
Add Comment
Please, Sign In to add comment