Locking around
Nikolaus Rath
Nikolaus at rath.org
Wed Aug 6 08:33:05 EDT 2008
Carl Banks <pavlovevidence at gmail.com> writes:
> Freaky... I just posted nearly this exact solution.
>
> I have a couple comments. First, the call to acquire should come
> before the try block. If the acquire were to fail, you wouldn't want
> to release the lock on cleanup.
>
> Second, you need to change notify() to notifyAll(); notify alone won't
> cut it. Consider what happens if you have two threads waiting for
> keys A and B respectively. When the thread that has B is done, it
> releases B and calls notify, but notify happens to wake up the thread
> waiting on A. Thus the thread waiting on B is starved.
You're right. Thanks for pointing it out.
Best,
-Nikolaus
--
»It is not worth an intelligent man's time to be in the majority.
By definition, there are already enough people to do that.«
-J.H. Hardy
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
More information about the Python-list
mailing list