三个读写器问题的python实现。
readerwriterlock的Python项目详细描述
三个读写器问题的python实现。
它不仅实现了读写器问题,还兼容python锁接口,其中包括对超时的支持。
有关读者-作者问题背后的理论,请参阅Wikipedia。
用法
根据访问优先级需要初始化新锁,线程将使用该锁:
reader priority(aka first readers writers problem)
from readerwriterlock import rwlock a = rwlock.RWLockRead()
writer priority(aka second readers writers problem)
from readerwriterlock import rwlock a = rwlock.RWLockWrite()
fair priority(aka third readers writers problem)
from readerwriterlock import rwlock a = rwlock.RWLockFair()
pythonic用法示例
with a.gen_rlock(): #Read stuff with a.gen_wlock(): #Write stuff
高级用法示例
b = a.gen_wlock() if b.acquire(blocking=True, timeout=5): #Do stuff b.release()
贡献
欢迎您投稿。
联系人
Project: | https://github.com/elarivie/pyReaderWriterLock |
---|---|
Bug tracker: | https://github.com/elarivie/pyReaderWriterLock/issues |
Author: | Éric Larivière ericlariviere@hotmail.com |