See points 2, 3 and 8 at http://clojure.org/refs

It is just a way to obtain the "change lock" of the ref in the dosync
transaction, without rewriting it. The alternative would be to
explicitly modify it to the same value as it was before, which is
potentially wasteful.

One possible case where this could be useful would be when you have some
synchronized state that should not be touched while another is.

Fictional elevator example:

(def elevator-doors (ref :closed))
(def elevator-floor (ref 1))

;; Elevator doors should NOT be opened while the elevator changes floor

(dosync (alter elevator-floor inc)
        (ensure elevator-doors))

/Linus


On 2014-06-19 17:35, Patrick Kristiansen wrote:
> I believe it is to avoid write skew. Check this Wikipedia page:
>
> http://en.m.wikipedia.org/wiki/Snapshot_isolation
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to