This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dbenbenn
Recipients
Date 2007-07-01.14:49:39
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
    >>> 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.
History
Date User Action Args
2007-08-23 14:58:12adminlinkissue1746071 messages
2007-08-23 14:58:12admincreate