[Python-3000] patch: bytes object PyBUF_LOCKDATA read-only and immutable support

Russell E. Owen rowen at cesmail.net
Wed Sep 12 20:53:25 CEST 2007


In article 
<ca471dc20709111449j717887dx18b7c18b2715c56a at mail.gmail.com>,
 "Guido van Rossum" <guido at python.org> wrote:

> I guess I would be inclined to propose separate flags for indicating
> the operation that the caller will attempt (read or write) and the
> level of locking (lock the buffer's address or also prevent anyone
> else from writing). Then a "classic read lock" would request read
> access while locking out writers (bsddb would use this); a "classic
> write lock" would request write access while locking out writers (your
> scratch area example would use this); others who don't really care if
> the data changes underneath them as long as it doesn't move (e.g.
> traditional I/O) could request read access without locking. I'm not
> sure if there's a use case to be made for write access without
> locking, but I wouldn't rule it out -- possibly when two threads share
> a memory area they might have their own protocol for locking it and
> might just both want to be able to write to (parts of) it.
> 
> What do you think? Another way to look at this would be to consider
> these 4 cases:
> 
> basic read access (I can read, others can read or write)
> locked read access (I can read, others can only read)
> basic write access (I can read and write, others can read or write)
> exclusive write access (I can read and write, no others can read or write)

Sounds much like the modes offered by an old operating system that had a 
very nice lock manager. The modes:
- concurrent read (others can read or write)
- protected read (others can read but not write)
- concurrent write (others can read or concurrent write)
- protected write (others can concurrent read)
- exclusive (no other locks allowed)
(as well as null to release the resource)

Some of these modes were intended for resources that are locked at 
multiple levels (which I don't think applies to array buffers). For 
example one might get a concurrent lock for a group of resources, then a 
protected lock for one resource. But as you say, there are some 
situations where concurrent write might be useful.

-- Russell



More information about the Python-3000 mailing list