A lock that times out but doesn't poll

Jive someone at microsoft.com
Tue Nov 23 18:08:42 EST 2004


Ironic, isn't it?  The whole idea of a condition variable is to avoid
sleeping and polling.  The polling soaks up CPU cycles, and the sleeping
introduces latency that might not be acceptable for a given application.

I presented two versions of sleepless timed condition variables in this NG a
year or two ago.  They hooted me down like an English kuneegut.

One version used an alarm clock thread.  From a very quick glance at your
code, I presume that's what you've done.  The other used a C coded timed
lock, something that's not in standard Python.  Why, I wonder?  I can't
imagine there are many platforms where you can't implement such a thing.  I
showed a C extension for MS Windows.

I made my Python module a drop-in replacement for the current threading
module, BTW.  I am uncomfortable with the existing package not only because
it uses polling, ("the evil from which we flee"), but also because it's so
convoluted.  Reading it, I have a hard time proving to myself that it's
correct.  If the package I posted is still on the net somewhere, take a look
at it and see just how simple it can be.

Now they will taunt me a second time.





More information about the Python-list mailing list