[Python-ideas] Extending language syntax

Andrew Barnert abarnert at yahoo.com
Tue Nov 12 23:50:47 CET 2013


On Nov 12, 2013, at 14:42, Charles-François Natali <cf.natali at gmail.com> wrote:

> 2013/11/12 Andrew Barnert <abarnert at yahoo.com>:
>> On Nov 12, 2013, at 10:25, Charles-François Natali <cf.natali at gmail.com> wrote:
>> 
>>> Of course. I probably wasn't clear, but I was actually referring to this part:
>>> 
>>>> Is there any implementation (like one of the PyPy sub projects) that uses refcounting, with interlocked increments if two interpreter threads are live but plain adds otherwise?
>>> 
>>> I'm not sure how one would do this without using locking/memory
>>> barriers (hence a large performance overhead).
>> 
>> A global "multithreading" flag. When you start a thread, it sets the flag in the parent thread, before starting the new thread. Both are guaranteed to see the True value. If there are any other threads, the value was already True.
> 
> That would probably work. The only remaining question is whether it'll
> actually yield a performance gain: as soon as you have more than one
> thread in the interpreter (even if it's idle), you'll end up doing
> atomic incref/decref all over the place, which will just kill
> performance (and will likely degrade with the number of threads
> because of increased contention to e.g. lock the memory bus).
> Atomic refcount just doesn't scale...

The point is that if you're _already_ doing atomic refcounts, or the equivalent (like CPython, which does refcounts under the GIL so they're implicitly atomic, which is even less parallel), you can avoid many of those refcounts.


More information about the Python-ideas mailing list