Popular recipes by Mateusz Kobos http://code.activestate.com/recipes/users/4178730/2011-09-28T21:45:04-07:00ActiveState Code RecipesReader-Writer lock with priority for writers (Python)
2011-09-28T21:45:04-07:00Mateusz Koboshttp://code.activestate.com/recipes/users/4178730/http://code.activestate.com/recipes/577803-reader-writer-lock-with-priority-for-writers/
<p style="color: grey">
Python
recipe 577803
by <a href="/recipes/users/4178730/">Mateusz Kobos</a>
(<a href="/recipes/tags/locking/">locking</a>, <a href="/recipes/tags/threads/">threads</a>).
Revision 2.
</p>
<p>The following class implements a reader-writer lock to use in the second readers-writers problem with python threads. In this problem, many readers can simultaneously access a share, and a writer has an exclusive access to this share. Additionally, the following constraints should be met: 1) no reader should be kept waiting if the share is currently opened for reading unless a writer is also waiting for the share, 2) no writer should be kept waiting for the share longer than absolutely necessary.</p>