For a lecture I have implemented the write-skew example from Mark Volkmann's article:
(defn write-skew [] (let [cats (ref 1) dogs (ref 1) john (future (dosync (when (< (+ @cats @dogs) 3) (alter cats inc)))) mary (future (dosync (when (< (+ @cats @dogs) 3) (alter dogs inc))))] (do @john @mary) (dosync (> (+ @cats @dogs) 3)))) (defn write-skew-demo [] (let [count-write-skews (atom 0)] (doseq [_ (range 25)] (when (write-skew) (swap! count-write-skews inc))) @count-write-skews)) (write-skew-demo) When I try to fix this program using ensure, i.e. using (ensure dogs) in john and (ensure cats) in mary, I find that it sometimes runs very slow. >From the docs it says "Allows for more concurrency than (ref-set ref @ref)". I would read that as "runs at least as fast as (ref-set ref @ref)", but using (ref-set dogs @dogs) instead of (ensure dogs) and the same with cats, does not exhibit these occasional runtime spikes. Am I misunderstanding something or is it a bug in ensure? Nils -- 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.