The future of "frozen" types as the number of CPU cores increases

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Feb 19 06:23:30 CET 2010


John Nagle wrote:

>    One way to implement locking is something like this:
> 
>    Mutable objects have a reference count field, a lock field,
> and an "owner" field.  Initially, the owner of an object is its thread.
> If an object's only reference is a field of a synchronized object, the
> owner is the synchronized object.

The trouble with that is that there will hardly ever be
"only one reference" to any object that you do anything
with, even just looking at it, because temporary references
come and go as the interpreter goes about its business.

A simple demonstration of this:

Python 2.5 (r25:51908, Apr  8 2007, 22:22:18)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> foo = (1, 2, 3)
 >>> import sys
 >>> sys.getrefcount(foo)
2

Even though you might think that there is only
one reference to foo, the very act of passing it
as a parameter to getrefcount() causes another
reference to come into existence temporarily.

-- 
Greg



More information about the Python-list mailing list