-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Brian Harring wrote:
> On Tue, Sep 20, 2005 at 06:55:44PM -0500, Paul Varner wrote:
> 
>>On Tue, 2005-09-20 at 18:34 -0500, Brian Harring wrote:
>>
>>>>Updated patch to add a semaphore to control access to the global
>>>>portage.config object. Unless anyone sees any other issues with this
>>>>patch, I will be placing it into gentoolkit.
>>>
>>>Reason for a semaphore over threading.Lock ?
>>
>>No reason other than I'm used to thinking of them as semaphores instead
>>of locks, so semaphore is what I searched for in the Python docs.
> 
> Need to make some chunks of the rewrite thread safe, so I poked a bit;
> python -m timeit -n 10000 -r 3 -s 'import threading;s=threading.Lock()' 
> 's.acquire();s.release()'
> around 1us
> python -m timeit -n 10000 -r 3 -s 'import threading;s=threading.Semaphore()' 
> 's.acquire();s.release()'
> 20us
> 
> Granted... It's being anal.  Just surprised me, and figured I'd poke 
> to find out if you had a specific reason for using sem over the 
> simpler (pretty much straight cpython) Lock :)
> ~harring

I haven't looked at the code, but I would gather that threading.lock is
what most would call a Mutex.  Semaphore's generally allow N number of
things to do a task ( say have 6 readers on an object, wait on semaphore
until all readers release, then write ).  Usually a performance if there
are more reads vs writes on your objects.

Thus the Lock is really a semaphore -> N = 1 which allows the kernel to
do some fun optimizing on it's operations.

Of course this is all conjecture since none of the __doc__ strings are
helpful :P
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iQIVAwUBQzFwF2zglR5RwbyYAQKP5g/+Og6ptvOFp+p4dWXBkKrgPEf/HjDP9Mdb
uinNZtytWu4myvDH+nNzz91gFrXQ9vyH6nSv62RZg20jOnAXGEkBZJAnhujteu5i
p9/ljSUphVvUHvzgixjGsJtKrbDNh72gwakniO57ZrjolKBxV3EZL87aJmoTd3Ye
j9h07mKzla8yOS8rswAS+uSnwWNEHoNbQtcVXnhFw0hhsyasi74Vwm2zoRZs6qgS
EHozcNmP0djn5pJPt5LNXhAOrd9myR/pkHQGAUKzvcpgfaRAFgflTJmrPqRAi61F
J90+0ZnxSBtplOTifkrOQxAtr///ZEHoe9Hfp5Dg/WInau6FODsEmjZ0j5g+F/6U
1V+50s4EMt4qcoGLPsGPj6HEy+M0SLF/Aie1VZesx/IwWf4jyy2Z6iHknM6WDGbh
1d5c73f9r/2DiV7GdkwpgoTxIAb4i/IcUQSqhB2O4vaJOvLubeJG4UTGPc/AxpEu
Vx1Ruvok6xDMOO5W7umYBpcD93ZBBRvdZiRj2uZVIl+AOM9aCejc+sW3KT7J+YLS
zlyIkfI29IJdt5QXYweMIX1QiLQSZZQTDKuDmeoqWVm7g48u5f/JLR9wBP+eJluw
4T92h5781vExy7TngGD5qGFMHwP8MMMi4UPB4tp6fLTEqkJeasa79LZrRHTEtNqQ
etlk6kngm50=
=P0ck
-----END PGP SIGNATURE-----
-- 
gentoo-portage-dev@gentoo.org mailing list

Reply via email to