E&S CVS Commit: PEAK - Made Once attributes thread-safe, to a point. While a "once" attribute is

pje at eby-sarna.com pje at eby-sarna.com
Mon Feb 24 15:32:01 EST 2003


Module Name:	PEAK
Committed By:	pje
Date:		Mon Feb 24 20:31:44 UTC 2003

Modified Files:
	PEAK/src/peak/binding: _once.c _once.pyx

Log Message:
Made Once attributes thread-safe, to a point.  While a "once" attribute is
being calculated, a special "lock" object is placed in the object's
dictionary.  This object just holds the thread ID of the calculating
thread.  If a re-entrant access to the attribute is made, the lock's ID is
checked for whether it's the same thread.  If it's the same thread, an
error is raised indicating that the attribute has a circular definition.
If it's not the same thread, the current thread pretends the value hasn't
been computed yet, and tries to compute it.

Note that in cases where the underlying once function and object are
properly constructed, this may occasionally result in two threads doing
the same work to calculate the attribute, but the results are always
the same.  In cases where the once function actually refers back to itself,
it's possible for competing threads to keep stealing the lock from each
other and thus never terminate.  Well, actually, you'll get a recursion
depth error on both threads, eventually.  So the limitations of this guard
technique should be quite acceptable for the intended uses of once
bindings, especially since this protection is really intended for class
attributes such as 'peak.model' metadata, not instance attributes.  Classes
*have* to be sharable between threads; instances rarely need to be.


To view diffs of this commit, you can use the following URL(s):
http://cvs.eby-sarna.com/PEAK/src/peak/binding/_once.c.diff?r1=1.4&r2=1.5
http://cvs.eby-sarna.com/PEAK/src/peak/binding/_once.pyx.diff?r1=1.4&r2=1.5

To generate a diff of this commit:
cvs rdiff -r1.4 -r1.5 PEAK/src/peak/binding/_once.c \
    PEAK/src/peak/binding/_once.pyx

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.




More information about the source-changes mailing list