Critical sections and mutexes

brueckd at brueckd at
Thu Oct 25 04:45:44 CEST 2001

On 24 Oct 2001, David Bolen wrote:

> > For example, if you have a work queue that you don't want to grow to some
> > extreme length you may decide to cap its size at 1000 elements. With 10
> > threads adding work to the list, occasionally they'll drop or hold a
> > packet of work too long or occasionally your list will grow to 1009
> > elements. No big deal: the drop/hold problem exists regardless of any sort
> > of locking, and you don't care that your list is 9 elements too big
> > because your requirement was simply "don't let it grow without bounds".
> Just be careful to fully document that fact in your code and avoid
> using this sort of example for newbie questions about threaded code.
> Otherwise what tends to happen is that someone believes that the code
> in question is really establishing a cap of 1000 (since they won't
> necessarily perform the same threaded analysis of the code you have)
> and this can lead to maintenance problems down the road.

No, no, no. That just means the code has really crummy comments. Why in
the world would "1000" show up in the comment? Comments, especially in
Python, should be level-of-intent, so the comment for this case would be
nearly exactly what I wrote in my post, i.e. "make sure the list doesn't
get too big".


More information about the Python-list mailing list