[Tutor] locks and threads
jtp at nc.rr.com
Sat Aug 2 20:36:00 CEST 2008
I'm trying to write a class that will acquire a lock before entering a
critical section, and then release it. Does this look like the right
way to go about accomplishing my goal?
grabLock = self.lock.acquire( 0 )
print 'acquired lock successfully'
print "did *not* obtain lock"
< ** what do I put here? ** >
if grabLock is True:
<do something "critical" here>
print 'released lock'
What should I be doing in the else: statement? If I can't grab the
lock, should I simply try again? Maybe a while loop that keeps trying
until I grab the lock? (I'm not really sure how I'm going to integrate
the 'try' statement with the while loop, though, to solve the problem
of not grabbing the lock)
More information about the Tutor