Python threading

  • Thread starter Brian Allen Vanderburg II
  • Start date
B

Brian Allen Vanderburg II

I'm doing some multi-threaded programming and before diving into the
C/C++ code I though I'd do some in Python first. I decided to read
through the threading module and I understand some of it, but I don't
understand this, though I'm sure it is easy:

The condition object has a method _is_owned, which is called if the lock
doesn't have one. The RLock does have one but a regular lock not. It
is supposed to return true if the lock is owned by the current thread:

def _is_owned(self):
# Return True if lock is owned by currentThread.
# This method is called only if __lock doesn't have _is_owned().
if self.__lock.acquire(0):
self.__lock.release()
return False
else:
return True

It seems that for a condition without an RLock but a Lock,
self.__lock.acquire(0) will return False even if the lock is owned by
another thread other than the current thread, so _is_owned would return
True even if the lock is owned by another thread.

B. Vanderburg II
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top