Message32434
> 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 |
|
Date |
User |
Action |
Args |
2007-08-23 14:58:13 | admin | link | issue1746071 messages |
2007-08-23 14:58:13 | admin | create | |
|