Queue can result in nested monitor deadlock

Alan Morgan amorgan at xenon.Stanford.EDU
Mon Apr 17 14:30:24 EDT 2006


In article <1145292096.906390.254280 at e56g2000cwe.googlegroups.com>,
Jonathan Amsterdam <jbamsterdam at gmail.com> wrote:
>If you don't want to call it deadlock, fine, but the program execution
>I describe will make no progress to the end of time. Thread 2 can never
>put anything in the queue, because Thread 1 holds M, and Thread 1 will
>never release M because that can only happen if someone puts something
>on the queue.

That's not a problem in the design of the queue class, it is a problem
in how you are using it.  Two possible solutions are:

1. Don't have the global lock on the object (or, at the very least,
   don't have that global lock taken when you read from the queue).
2. Don't use a syncronized queue.  If the only access to the queue is
   through the object and the object is protected then you don't need
   a synchronized queue.

Alan
-- 
Defendit numerus



More information about the Python-list mailing list