Producer-consumer threading problem

Carl Banks pavlovevidence at
Wed Jun 11 07:59:49 CEST 2008

On Jun 10, 11:33 pm, George Sakkis <george.sak... at> wrote:
> I'd like some feedback on a solution to a variant of the producer-
> consumer problem. My first few attempts turned out to deadlock
> occasionally; this one seems to be deadlock-free so far but I can't
> tell if it's provably correct, and if so, whether it can be
> simplified.
> The generic producer-consumer situation with unlimited buffer capacity
> is illustrated at
> That approach assumes that the producer will keep producing items
> indefinitely, otherwise the consumer ends up waiting forever. The
> extension to the problem I am considering requires the consumer to be
> notified not only when there is a new produced item, but also when
> there is not going to be a new item so that it stops waiting.

Sounds like a sentinel would work for this.  The producer puts a
specific object (say, None) in the queue and the consumer checks for
this object and stops consuming when it sees it.  But that seems so
obvious I suspect there's something else up.

Carl Banks

More information about the Python-list mailing list