Reader-Writer lock with priority for writers in Python

I needed 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.

Surprisingly, I wasn’t able to find an implementation of such a synchronization object that met some basic common-sense requirements: 1) simple, clear implementation, 2) tested with some basic unit tests. So, I wrote my own version — it is placed here: http://code.activestate.com/recipes/577803-reader-writer-lock-with-priority-for-writers .

This entry was posted in Python. Bookmark the permalink.

4 Responses to Reader-Writer lock with priority for writers in Python

  1. Ernest says:

    I read a lot of interesting articles here. Probably you spend a lot of
    time writing, i know how to save you a lot of time, there is an online tool that
    creates high quality, SEO friendly posts in minutes, just type
    in google – k2seotips unlimited content

  2. weight loss says:

    Interesting posts you post on your blog, i have shared this article
    on my twitter

  3. matt says:

    Hi there,
    Are you still maintaining the RWLock and is it on github? This is a nice implementation of RWLock but I think there might be some potential problem when several writer want to acquire the lock. I would be glad to fork the project if it’s already on github. If it’s not, do you mind I fork it on github?

    Thanks,
    Matt

Leave a Reply to weight loss Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>