[Zope-dev] thread locking and ZODB

Terry Kerr terry@bizarsoftware.com.au
Wed, 12 Sep 2001 12:35:02 +1000


Hi,

I have a method which increments an attribute on the current object.  I
have created a thread lock so that multiple threads accessing the method
simultaneously cannot stuff up the attribute value:

lock = thread.allocate_lock()

def nextOrderNumber(self):
    lock.acquire()
    self._order_number = self._order_number + 1
    lock.release()
    return str(self._order_number)

My concern is that even though a second thread is halted at
"lock.acqure()" while the first thread updates the order_number, that
the second thread has an 'out of date' version of 'self' with the
original order_number value in it, hence, is still returning the
incorrect order_number.

Do I need to explicity get the order_number attribute from the ZODB
somehow, rather than grabbing it from 'self'?

terry

-- 
Terry Kerr (terry@bizarsoftware.com.au)
Bizar Software Pty Ltd (www.bizarsoftware.com.au)
Phone: +61 3 9563 4461
Fax: +61 3 9563 3856
ICQ: 79303381