Dear list,

I've got two threads that update the same location. One of them takes a lot 
of time. Given this, my question is if there is a reason to prefer an atom 
or a ref? 

i.e.:

1) with an atom:

(def a (atom []))
;; the slow thread
(future (swap! a #(do (Thread/sleep 5000) (conj % 1))))
;; the fast thread:
(future (swap! a #(do (conj % 2))))

2) with a ref:

(def r (ref []))
;; the slow thread
(future (dosync (alter r #(do (Thread/sleep 5000) (conj % 1))))
;; the fast thread:
(future (dosync (alter r conj 2))))

Thanks!

-- 
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