It seems I have an example that shows difference between commute and
alter.
Here it is:
(defn my-inc [x] (dosync (Thread/sleep 1000) (inc x)))

****alter***
(def x (ref 0))
(do
       (def fut (future (do (Thread/sleep 300) (dosync (alter x inc))
@x)))
       (dosync (println @x)(alter x my-inc)(println @x))
       @x)
output:
0
1
2 (it's the in-transaction value)
2 (it's the post-commit value)

***commute***
(def x (ref 0))
(do
       (def fut (future (do (Thread/sleep 300) (dosync (alter x inc))
@x)))
       (dosync (println @x)(commute x my-inc)(println @x))
        @x)
output:
0
1 (it's the in-transaction value)
2(it's the post-commit value)

So this example demonstrate difference between commute and alter.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to