There's a correct, updated version here: http://clojure.org/concurrent_programming
(import '(java.util.concurrent Executors)) (defn test-stm [nitems nthreads niters] (let [refs (map ref (replicate nitems 0)) pool (Executors/newFixedThreadPool nthreads) tasks (map (fn [t] (fn [] (dotimes [n niters] (dosync (doseq [r refs] (alter r + 1 t)))))) (range nthreads))] (doseq [future (.invokeAll pool tasks)] (.get future)) (.shutdown pool) (map deref refs))) --Steve On Jan 3, 2009, at 2:58 PM, wubbie wrote:
Hi, What's the correct syntax for this code -- from clojure manual. (import '(java.util.concurrent Executors)) (defn testāstm [nitems nthreads niters] (let [refs (map ref (replicate nitems 0)) pool (. Executors (newFixedThreadPool nthreads)) tasks (map (fn [t] (fn [] (dotimes n niters (dosync (doseq r refs (alter r + 1 t)))))) (range nthreads))] (doseq future (. pool (invokeAll tasks)) (. future (get))) (. pool (shutdown)) (map deref refs))) --~--~---------~--~----~------------~-------~--~----~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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---
smime.p7s
Description: S/MIME cryptographic signature