Gentoo Archives: gentoo-portage-dev

From: Alec Warner <warnera6@×××××××.edu>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] PATCH: gentoolkit: Make portage.config object a global object
Date: Wed, 21 Sep 2005 14:38:39
Message-Id: 43317017.9030108@egr.msu.edu
In Reply to: Re: [gentoo-portage-dev] PATCH: gentoolkit: Make portage.config object a global object by Brian Harring
1 -----BEGIN PGP SIGNED MESSAGE-----
2 Hash: SHA1
3
4 Brian Harring wrote:
5 > On Tue, Sep 20, 2005 at 06:55:44PM -0500, Paul Varner wrote:
6 >
7 >>On Tue, 2005-09-20 at 18:34 -0500, Brian Harring wrote:
8 >>
9 >>>>Updated patch to add a semaphore to control access to the global
10 >>>>portage.config object. Unless anyone sees any other issues with this
11 >>>>patch, I will be placing it into gentoolkit.
12 >>>
13 >>>Reason for a semaphore over threading.Lock ?
14 >>
15 >>No reason other than I'm used to thinking of them as semaphores instead
16 >>of locks, so semaphore is what I searched for in the Python docs.
17 >
18 > Need to make some chunks of the rewrite thread safe, so I poked a bit;
19 > python -m timeit -n 10000 -r 3 -s 'import threading;s=threading.Lock()' 's.acquire();s.release()'
20 > around 1us
21 > python -m timeit -n 10000 -r 3 -s 'import threading;s=threading.Semaphore()' 's.acquire();s.release()'
22 > 20us
23 >
24 > Granted... It's being anal. Just surprised me, and figured I'd poke
25 > to find out if you had a specific reason for using sem over the
26 > simpler (pretty much straight cpython) Lock :)
27 > ~harring
28
29 I haven't looked at the code, but I would gather that threading.lock is
30 what most would call a Mutex. Semaphore's generally allow N number of
31 things to do a task ( say have 6 readers on an object, wait on semaphore
32 until all readers release, then write ). Usually a performance if there
33 are more reads vs writes on your objects.
34
35 Thus the Lock is really a semaphore -> N = 1 which allows the kernel to
36 do some fun optimizing on it's operations.
37
38 Of course this is all conjecture since none of the __doc__ strings are
39 helpful :P
40 -----BEGIN PGP SIGNATURE-----
41 Version: GnuPG v1.4.1 (GNU/Linux)
42 Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
43
44 iQIVAwUBQzFwF2zglR5RwbyYAQKP5g/+Og6ptvOFp+p4dWXBkKrgPEf/HjDP9Mdb
45 uinNZtytWu4myvDH+nNzz91gFrXQ9vyH6nSv62RZg20jOnAXGEkBZJAnhujteu5i
46 p9/ljSUphVvUHvzgixjGsJtKrbDNh72gwakniO57ZrjolKBxV3EZL87aJmoTd3Ye
47 j9h07mKzla8yOS8rswAS+uSnwWNEHoNbQtcVXnhFw0hhsyasi74Vwm2zoRZs6qgS
48 EHozcNmP0djn5pJPt5LNXhAOrd9myR/pkHQGAUKzvcpgfaRAFgflTJmrPqRAi61F
49 J90+0ZnxSBtplOTifkrOQxAtr///ZEHoe9Hfp5Dg/WInau6FODsEmjZ0j5g+F/6U
50 1V+50s4EMt4qcoGLPsGPj6HEy+M0SLF/Aie1VZesx/IwWf4jyy2Z6iHknM6WDGbh
51 1d5c73f9r/2DiV7GdkwpgoTxIAb4i/IcUQSqhB2O4vaJOvLubeJG4UTGPc/AxpEu
52 Vx1Ruvok6xDMOO5W7umYBpcD93ZBBRvdZiRj2uZVIl+AOM9aCejc+sW3KT7J+YLS
53 zlyIkfI29IJdt5QXYweMIX1QiLQSZZQTDKuDmeoqWVm7g48u5f/JLR9wBP+eJluw
54 4T92h5781vExy7TngGD5qGFMHwP8MMMi4UPB4tp6fLTEqkJeasa79LZrRHTEtNqQ
55 etlk6kngm50=
56 =P0ck
57 -----END PGP SIGNATURE-----
58 --
59 gentoo-portage-dev@g.o mailing list