[issue11618] Locks broken wrt timeouts on Windows

Kristján Valur Jónsson report at bugs.python.org
Mon Mar 21 21:12:29 CET 2011


Kristján Valur Jónsson <kristjan at ccpgames.com> added the comment:

There is no barrier in use on the read part.  I realize that this is a subtle point, but in fact, the atomic functions make no memory barrier guarantees either (I think).  And even if they did, you are not using a memory barrier when you read the 'timeouts' to perform the subtraction.  On a multiprocessor machine the two values can easily fall on two cache lines and become visible to the other cpu in a random fashion.  In other words:  One cpu decreases the "owner" and "timeouts" at about the same time.  A different thread, on a different cpu may see the decrease in "owner" but not the decrease in "timeouts" until at some random later point.

Lockless algorithms are notoriously hard and it is precisely because of subtle pitfalls like these.  I could even be wrong about the above, but that would not be blindingly obvious either.  I'm sure you've read something similar but this is where I remember seeing some of this stuff mentioned:  http://msdn.microsoft.com/en-us/library/ee418650(v=vs.85).aspx

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11618>
_______________________________________


More information about the Python-bugs-list mailing list