[Python-ideas] Monitor implementation for the stdlib?
rhamph at gmail.com
Mon Oct 22 18:22:00 CEST 2007
On 10/22/07, George Sakkis <george.sakkis at gmail.com> wrote:
> On 10/22/07, Adam Olsen <rhamph at gmail.com> wrote:
> > A method is often *NOT* the
> > correct granularity to achieve a thread-safe API! Consider:
> > l = ... some "thread-safe" list ...
> > if l:
> > x = l.pop()
> > There's two method calls, so you cannot guarantee the object hasn't
> > changed between them. I get the impression this is regarded as a
> > major mistake in Java's extensive use of monitors - plastering locks
> > everywhere just isn't good enough.
> My Java's kinda rusty but IIRC one can use synchronized blocks on an
> object to achieve finer granularity.
You need coarser granularity to achieve correctness in this case.
Adam Olsen, aka Rhamphoryncus
More information about the Python-ideas