[ZODB-Dev] Thread Safety, Reaimed

Norfleet, Sheppard S. sheppard.norfleet at ngc.com
Thu Aug 7 13:36:07 EDT 2003


Request Verification:

It appears to me that its not a true singleton, and I bet its not thread
safe.  The question is, for every instance of borg are you accessing just
one lock object, !OR! is it creating a new lock object and initializing it
to the others state at that moment in time.  if its the former then it is
thread safe, if its the later then it is not.

Thanks 

Shep



-----Original Message-----
From: Stefan H. Holek [mailto:stefan at epy.co.at]
Sent: Thursday, August 07, 2003 2:20 PM
To: Norfleet, Sheppard S.
Cc: 'zodb-dev at zope.org'
Subject: RE: [ZODB-Dev] Thread Safety, Reaimed


Hm, then try a Borg pattern, maybe.

  # Module GlobalLock.py
  import threading

  class GlobalLock:
      __shared_state = {
          '_lock': threading.Lock()
          }
      def __init__(self):
          self.__dict__ = self.__shared_state
      def acquire(self):
          self._lock.acquire()
      def release(self):
          self._lock.release()

Now you can do things like:

  from GlobalLock import GlobalLock

  GlobalLock().acquire()
  ...
  GlobalLock().release()

HTH,
Stefan


--On Donnerstag, 07. August 2003 10:44 -0700 "Norfleet, Sheppard S." 
<sheppard.norfleet at ngc.com> wrote:

> Stefan,
>
> Thanks for the response.
>
> I tried that, but I get an UnboundLocalError when I try to reference the
> lock from the Zope Object.
>
> Regards,
>
> Shep
>

--
The time has come to start talking about whether the emperor is as well
dressed as we are supposed to think he is.               /Pete McBreen/



More information about the ZODB-Dev mailing list