Looking at the source code in LockingTransaction.java, that doesn't
seem to always be the case. I see this:
f.fn.applyTo(RT.cons(vals.get(ref), f.args))
vals is a HashMap of in-transaction values, not most recently committed values.
Inside a transaction, Refs get in-transaction values if you do a
ref-set or alter on them.
Within a transaction you can ref-set or alter a Ref and then do a
commute on the same Ref.
You can't reverse the order. Once you do a commute on a Ref, you can't
do a ref-set or alter on it in the same transaction.
During transaction commit and immediately before the commute functions
for the Ref are called, it determines whether the Ref has an
in-transaction value, meaning that ref-set or alter was called on it.
If it does not then the most recently committed value for the Ref is
used for the in-transaction value.
So I think it is only partially true to say that when commute
functions are rerun during a commit, they use the most recently
committed values of Refs. That only happens if ref-set and alter were
not used on the Ref before the call to commute.
Am I understanding this correctly?
--
R. Mark Volkmann
Object Computing, Inc.
Not really. If this transaction is succeeding, and it has written to a
ref prior to its commute, then those writes *are* the most recently
committed value, committed now as a prior part of the same
transaction.
Rich
Thanks for explaining that! I see what you're saying, but I also see
how someone, like me ;-), could be confused by the doc string.
When the code in question is running, the commit hasn't completed yet.
It doesn't seem correct to say "those writes *are* the most recently
committed value", but rather "those writes *will become* the most
recently committed value. I hope I'm not just splitting hairs, but it
seems that "most-recently-committed-value-of-ref" implies that its a
value that can be seen now by all threads.
Maybe this is splitting hairs too, but if the code in a commute
function throws an exception when it is called during the commit then
values set before the commutes in the transaction body really will not
become the most recently committed value.
That said, I can't think of a concise way to explain this in the doc string.
Nor will the commute happen.
Rich
Patch applied to master and 1.0.x - thanks!
Rich