Message32432
>>> import mutex
>>> print mutex.mutex.testandset.__doc__
Atomic test-and-set -- grab the lock if it is not set,
return True if it succeeded.
The above docstring is wrong: the method is not atomic. This is easy to see by inspecting the method's code:
def testandset(self):
"""Atomic test-and-set -- grab the lock if it is not set,
return True if it succeeded."""
if not self.locked:
self.locked = 1
return True
else:
return False
Therefore, it is possible for two threads to lock the same mutex simultaneously. So the mutex module cannot be used for mutual exclusion.
The documentation for mutex says "The mutex module defines a class that allows mutual-exclusion via acquiring and releasing locks." [http://docs.python.org/lib/module-mutex.html]. Perhaps it would be a good idea to make the module actually do what the documentation says. |
|
Date |
User |
Action |
Args |
2007-08-23 14:58:12 | admin | link | issue1746071 messages |
2007-08-23 14:58:12 | admin | create | |
|