Popular recipes by Stefan Behnel http://code.activestate.com/recipes/users/4174506/2010-07-27T20:25:20-07:00ActiveState Code RecipesFast, re-entrant, optimistic lock implemented in Cython (Python)
2010-07-27T20:25:20-07:00Stefan Behnelhttp://code.activestate.com/recipes/users/4174506/http://code.activestate.com/recipes/577336-fast-re-entrant-optimistic-lock-implemented-in-cyt/
<p style="color: grey">
Python
recipe 577336
by <a href="/recipes/users/4174506/">Stefan Behnel</a>
(<a href="/recipes/tags/concurrency/">concurrency</a>, <a href="/recipes/tags/lock/">lock</a>, <a href="/recipes/tags/locking/">locking</a>).
Revision 3.
</p>
<p>This is a C-level implementation of a fast, re-entrant, optimistic lock for CPython. It is written in Cython. Under normal conditions, it is about 10x faster than threading.RLock because it avoids all locking unless two or more threads try to acquire it at the same time. Under congestion, it is still about 10% faster than RLock due to being implemented in Cython.</p>