On Nov 26, 2:35 pm, "Mark Volkmann" <[EMAIL PROTECTED]> wrote:
> On Wed, Nov 26, 2008 at 1:13 PM, Shawn Hoover <[EMAIL PROTECTED]> wrote:
>
> > On Wed, Nov 26, 2008 at 1:55 PM, Mark Volkmann <[EMAIL PROTECTED]>
> > wrote:
>
> >> The documentation for commute says "Sets the in-transaction-value of
> >> ref ...". This implies to me that when the transaction ends, the ref
> >> will have its previous value.
>
> >> (def myRef (ref 19))
> >> (dosync (commute myRef inc)) -> 20
> >> @myRef -> 20
>
> >> Why isn't the value of the last line 19?
>
> >> --
> >> R. Mark Volkmann
> >> Object Computing, Inc.
>
> > "in-transaction" just means that the new value is seen if code later in the
> > transaction dereferences myRef, while the rest of the program (other
> > threads) will not see the new value until the transaction succeeds. Once the
> > transaction commits, then the rest of the program will also see the new
> > value. If you need something that takes on a new value within a defined
> > scope and then pops off to the previous value, check out Vars and binding.
>
> Is that the main difference between commute and set-ref?
> commute sets a value that isn't seen outside the transaction until the
> transaction ends.
> set-ref sets a value that is immediately seen outside the transaction
> before it ends.
>
Not at all. Nothing done in a transaction is seen outside until the
transaction commits.
You need to read (doc commute) all the way through, where it
subsequently says:
At the commit point of the transaction, sets the value of ref to be:
(apply fun most-recently-committed-value-of-ref args)
... commute allows for more concurrency than ref-set.
i.e. the commute fn gets called twice.
The point about the in-transaction value with commute is that it may
differ from the post-commit value, as the effect of commute is a
function of the value of the ref at commit time.
See also:
http://clojure.org/refs
Rich
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---