Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- class Reader(threading.Thread):
- def run(self):
- while True:
- with RW.LW:
- pass
- with RW.LR:
- RW.read_count += 1
- readData(RW.data)
- with RW.LR:
- RW.read_count -= 1
- RW.LR.notify()
- doMoreWork()
- class Writer(threading.Thread):
- def run(self):
- while True:
- with RW.LW:
- waiting = True
- while waiting:
- with RW.LR:
- if RW.read_count == 0:
- updateData(Rw.data)
- waiting = False
- else:
- # use wait/notify to avoid busy waiting
- while RW.read_count != 0:
- RW.LR.wait()
- doOtherWork()
Add Comment
Please, Sign In to add comment