[Python-ideas] Extending language syntax

Andrew Barnert abarnert at yahoo.com
Tue Nov 12 18:56:20 CET 2013


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

> 2013/11/12 Andrew Barnert <abarnert at yahoo.com>:
>> 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? In such an implementation, I think the cost of checking a second flag to avoid the interlocked increment would, at least on many platforms (including x86, x86_64, and arm9), be comparatively very cheap, and if used widely could provide big benefits.
> 
> How would you do this in a thread-safe way without atomic operations,
> or at least memory barriers?

The whole point of a "permanent" flag would be that it's only set at object creation time and never modified, and the object never gets cleaned up.

That means you can just check the flag, without an atomic operation, and if it's set you can skip the (slow/cache-killing) atomic increment or decrement. 


More information about the Python-ideas mailing list