[Python-Dev] Re: post mortem after threading deadlock?

Tim Peters tim.one@home.com
Wed, 25 Jul 2001 18:11:16 -0400


[Skip Montanaro]
> ...
> However, if you read my problem as a thinly veiled enhancement request,
> the people most likely to be able to implement such a thing are on this
> list.  I sort of suspect that from the Python level about all I can do
> today is what I'm already doing - poking around the various locks
> and semaphores that the threads all share.

I've got better advice <wink>:  Never use semaphores for anything.  Never
use locks except for dirt-simple one- or two-line critical sections.  For
everything but the latter, always use condition variables.  They're the only
synch protocol I've seen that non-specialist thread programmers can use
without routinely screwing themselves.  The genius of the condvar protocol
is that, used correctly, you *always* run-time test your crucial assumptions
about non-local state (and automatically do so under the protection of a
critical section), and *always* loop back to try again if your hopes or
assumptions turn out not to be true.  This saves you from a universe of
possible problems with non-local state changing in unanticipated ways.

if-you-had-used-condvars-you-wouldn't-be-debugging-now-ly y'rs  - tim