[Python-ideas] Extending language syntax

Charles-François Natali cf.natali at gmail.com
Tue Nov 12 23:42:22 CET 2013


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...

cf


More information about the Python-ideas mailing list