This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Read Write lock
Type: enhancement Stage: test needed
Components: Extension Modules Versions: Python 3.2
Status: closed Resolution: later
Dependencies: Superseder:
Assigned To: Nosy List: loewis, loupgaroublond, rutsky, terry.reedy
Priority: normal Keywords: patch

Created on 2007-06-27 18:08 by loupgaroublond, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit loupgaroublond, 2007-06-27 18:08 A reverse semaphore and a multilock loupgaroublond, 2007-07-06 17:51 revision 2 - a patch to
Messages (6)
msg52800 - (view) Author: Yaakov Nemoy (loupgaroublond) Date: 2007-06-27 18:08
This is a Lock for handling both multiple readers and a single or multiple writers.  It allows any number of readers to acquire a 'lock' via a modified semaphore.  It also allows any number of writers to try to acquire a lock, which signals the lock to block new readers from acquiring, until the writers have had a chance to do their business.  Through a simple lock, multiple writers can wait in line, although only one writer can actually write at a time.

It also lets the developer use the 'with' statement, via  methods that return contextmanagers.

I actually had a couple of unimplemented ideas.

A) Writers can specify a deadline (or even use a default) such that after the deadline passes, the lock can use a callback to rollback/kill/pause readers, so that the writer doesn't wait an eternity.

B) Allowing the semaphore to have an upper limit of allowed readers (or anythings), Since I don't need it, i never programmed it, but it should be fairly trivial to implement if there is any demand.
msg52801 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-06-30 17:38
The patch is unacceptable in its current form:
- it should be provided as a patch to, not as a separate module
- it should have a name that follows "the convention", which seems to be that 
  it should have "reader" and "writer" in its name (or "rw"). See how C# and
  Java do it (and other libraries you can find that provide such a mechanism)
- it needs documentation
- it needs tests.
msg52802 - (view) Author: Yaakov Nemoy (loupgaroublond) Date: 2007-07-06 17:51
Out of those four deliverables, i have three (albeit the easiest).  Attached is a copy of the newly dubbed ReadWriteLock along with his pal ReverseSemaphore, and two new helper objects ReadLock and WriteLock (can you do the java equivalent of anonymous inner classes?).  This is a patch on the copy of that is delivered with Fedora 7 aka:
Version: 2.5
Release: 12.fc7

which was done for convenience (my convenience that is, and certainly not yours ;))

The naming convention has been changed to follow that of Java's, the acquire/release pattern notwithstanding.  There is some documentation via docstrings, as I wasn't sure of the best way to document this module.

The last point, unit testing, I am not sure as the best way to go about a multithreaded unit test.  I can look into it later, but honestly, it's friday, and there are two days left till monday.

Please let me know if I am on the right track here at least.

File Added:
msg52803 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-07-06 21:58
I'm skeptical about the implementation strategy chosen, in particular about the notion of a reversed semaphore, which I have never heard of. Is there prior art for such a construct?
Traditionally, rw locks provide certain fairness guarantees - why doesn't this implementation? To put it more bluntly: why is that so extravagant?

As for the style of the patch itself:
- please provide it as a unified or context diff. Making it relative to some released 2.5 version is fine.
- please drop the redundant pass statements
- documentation patches should be made against Doc/lib/libthreading.tex. If you cannot write LaTeX, just adding sections in plain text is fine.
- tests should be added to Lib/test/
msg113375 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-09 04:09
Yaakov, do you have any interest in this, or should we close this.
msg113521 - (view) Author: Yaakov Nemoy (loupgaroublond) Date: 2010-08-10 10:22
Feel free to close this. I can't commit to maintaining this right now, if i ever find the time, i can reopen the issue.
Date User Action Args
2022-04-11 14:56:25adminsetgithub: 45133
2013-02-26 07:52:40rutskysetnosy: + rutsky
2010-08-10 17:04:07terry.reedysetstatus: open -> closed
resolution: later
2010-08-10 10:22:18loupgaroublondsetmessages: + msg113521
2010-08-09 04:09:26terry.reedysetnosy: + terry.reedy

messages: + msg113375
versions: + Python 3.2, - Python 3.1, Python 2.7
2009-04-06 10:31:51ajaksu2setstage: test needed
type: enhancement
versions: + Python 3.1, Python 2.7, - Python 2.6
2007-06-27 18:08:03loupgaroublondcreate