Critical sections and mutexes

David Bolen db3l at fitlinxx.com
Wed Oct 24 18:51:58 EDT 2001


<brueckd at tbye.com> writes:

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

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list