How to go about. On read/write locks

Diez B. Roggisch deets at nospam.web.de
Mon Apr 6 17:23:47 EDT 2009


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

I was going to suggest a similar approach but refused to because of a 
problem I see with your code as well - if the readers are reading very 
fast (the OP didn't state what his actual application is, so it might 
not be a consumer-producer scheme which I don't think a dict would be 
the natural choice anyway) they can block the writer from writing 
alltogether.


Or do I miss something here?

Diez



More information about the Python-list mailing list