How to go about. On read/write locks
Piet van Oostrum
piet at cs.uu.nl
Tue Apr 7 13:29:40 CEST 2009
>>>>> "Diez B. Roggisch" <deets at nospam.web.de> (DBR) wrote:
>>> This is a classical synchronization problem with a classical solution:
>>> You treat the readers as a group, and the writers individually. So you
>>> have a write lock that each writer has to acquire and release, but it is
>>> acquired only by the first reader and released by the last one.
>>> Therefore you need a counter of the number of readers, and manipulations
>>> of this counter must be protected by another lock.
>DBR> I was going to suggest a similar approach but refused to because of a
>DBR> problem I see with your code as well - if the readers are reading very fast
>DBR> (the OP didn't state what his actual application is, so it might not be a
>DBR> consumer-producer scheme which I don't think a dict would be the natural
>DBR> choice anyway) they can block the writer from writing alltogether.
>DBR> Or do I miss something here?
Yes, you missed note 2 at the end of my posting.
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list