@@ -14,6 +14,9 @@ class Reference(object):
1414 Compare to Haskell's ``IORef`` or Clojure's ``atom``.
1515 """
1616
17+ # TODO: Add modify_atomic that either uses a lock or a low-level
18+ # compare-and-set operation.
19+
1720 def __init__ (self , initial ):
1821 self ._value = initial
1922
@@ -24,6 +27,9 @@ def read(self):
2427 def modify (self , transformer ):
2528 """
2629 Return an Effect that updates the value with ``fn(old_value)``.
30+
31+ This is not guaranteed to be linearizable if multiple threads are
32+ modifying the reference at the same time.
2733 """
2834 return Effect (ModifyReference (ref = self , transformer = transformer ))
2935
@@ -37,6 +43,9 @@ class ReadReference(object):
3743class ModifyReference (object ):
3844 """
3945 Intent that modifies a Reference value in-place with a transformer func.
46+
47+ This intent is not necessarily linearizable if multiple threads are
48+ modifying the same reference at the same time.
4049 """
4150
4251
@@ -51,9 +60,8 @@ def perform_modify_reference(dispatcher, intent):
5160 """
5261 Performer for :obj:`ModifyReference`.
5362
54- Note that while :obj:`ModifyReference` is designed to allow strong
55- consistency, this performer is _not_ threadsafe, in the sense that it's
56- possible to overwrite unobserved values. This may change in the future.
63+ This performer is not linearizable if multiple physical threads are
64+ modifying the same reference at the same time.
5765 """
5866 new_value = intent .transformer (intent .ref ._value )
5967 intent .ref ._value = new_value
0 commit comments