The future of Python immutability

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Sep 4 00:38:05 CEST 2009


En Thu, 03 Sep 2009 15:03:13 -0300, John Nagle <nagle at animats.com>  
escribió:

>      Python's concept of immutability is useful, but it could be more
> general.
>
>      Immutability is interesting for threaded programs, because
> immutable objects can be shared without risk.  Consider a programming
> model where objects shared between threads must be either immutable or
> "synchronized" in the sense that Java uses the term.  Such programs
> are free of most race conditions, without much programmer effort to
> make them so.

In the current CPython implementation, every object has a reference count,  
even immutable ones. This must be a writable field - and here you have  
your race condition, even for immutable objects.

-- 
Gabriel Genellina




More information about the Python-list mailing list