frozendict

John Nagle nagle at animats.com
Mon Feb 13 16:15:36 EST 2012


On 2/10/2012 9:52 PM, 88888 Dihedral wrote:
> 在 2012年2月11日星期六UTC+8上午2时57分34秒,John Nagle写道:
>> On 2/10/2012 10:14 AM, Nathan Rice wrote:
>>>>> Lets also not forget that knowing an object is immutable lets you do a
>>>>> lot of optimizations; it can be inlined, it is safe to convert to a
>>>>> contiguous block of memory and stuff in cache, etc.  If you know the
>>>>> input to a function is guaranteed to be frozen you can just go crazy.
>>>>> Being able to freeze(anyobject) seems like a pretty clear win.
>>>>> Whether or not it is pythonic is debatable.  I'd argue if the meaning
>>>>> of pythonic in some context is limiting, we should consider updating
>>>>> the term rather than being dogmatic.
>>
>>       A real justification for the ability to make anything immutable is
>> to make it safely shareable between threads.  If it's immutable, it
>> doesn't have to be locked for access.  Mozilla's new "Rust"
>> language takes advantage of this.  Take a look at Rust's concurrency
>> semantics.  They've made some progress.
>>
>> 					John Nagl
>
>
> Lets model the system as an asynchronous set of objects with multiple threads
> performing operatons on objects as in the above.

    I'd argue for a concurrency system where everything is either 
immutable, unshared, synchronized, or owned by a synchronized object.
This eliminates almost all explicit locking.

    Python's use of immutability has potential in that direction, but
Python doesn't do anything with that concept.

					John Nagle




More information about the Python-list mailing list