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-02.09:23:00
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
> How are you using mutex with threads, can you please provide some
information.

I'm attaching an example program that demonstrates two threads both locking the same mutex at the same time.

> If muobj is an instance of mutex class.
> muobj.testandset() for process-a will set the lock.
> muobj.testandset() for process-b will be dealt with self.lock = True and
> wont be able to set.

That isn't correct.  It is possible for testandset to return True in both thread-a and thread-b.  What can happen is the following:

1) Thread a calls testandset().  It executes the line "if not self.locked", and finds the result to be True.
2) The OS switches threads.
3) Thread b calls testandset().  It executes the line "if not self.locked", and finds the result to be True.
4) Thread b sets "self.locked = 1" and returns True
5) Thread a sets "self.locked = 1" and returns True
File Added: ex.py
History
Date User Action Args
2007-08-23 14:58:13adminlinkissue1746071 messages
2007-08-23 14:58:13admincreate