On Dec 29, 4:17 am, k3xji <sum...@gmail.com> wrote: > On 29 Aralýk, 11:52, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> > wrote: > > > En Mon, 29 Dec 2008 05:56:10 -0200, k3xji <sum...@gmail.com> escribió: > snip > > > class wthread(threading.Thread): > > > def run(self): > > > try: > > > #GLOBAL_LOCK.acquireWrite() > > > #GLOBAL_LOCK.acquire_write() > > > GLOBAL_LOCK.acquire() > > > for i in range(GLOBAL_LOOP_COUNT): > > > GLOBAL_VAR = 4 > > > finally: > > > #GLOBAL_LOCK.release_write() > > > GLOBAL_LOCK.release() > > > Note that the thread acquires the lock ONCE, repeats several thousand > > times an assignment to a *local* variable called GLOBAL_VAR (!) snip > > class wthread(threading.Thread): > > def run(self): > > global GLOBAL_VAR > > for i in xrange(GLOBAL_LOOP_COUNT): > > GLOBAL_LOCK.acquire() > > try: > > GLOBAL_VAR += 1 > > finally: > > GLOBAL_LOCK.release() > > With that, primitive locks perform 10 times better than Read-Write > lock. See above. snip
Gabriel's point (one of them) was that 'GLOBAL_VAR' isn't global in your example. Your 'wthread' objects aren't sharing anything. He added the 'global GLOBAL_VAR' statement, which is important -- http://mail.python.org/mailman/listinfo/python-list