Re: possible side-effect/problem in http://clojure.org/concurrent_programming

2013-06-14 Thread Alan Malloy
The laziness of map is irrelevant here, because .invokeAll is treating it as a collection and realizing it all immediately. Your version with for is just as lazy. What's actually changed is that your map and for produce entirely different outputs: the version with map calls test-fn, and the ver

Re: possible side-effect/problem in http://clojure.org/concurrent_programming

2013-06-14 Thread Raoul Duke
> But only one task was active at a time, although Executors was configured > with 4 threads. It occurred to me that map itself is lazy and it is realized > in doseq one at a time. A possible fix is to use for instead of map to > generate tasks almost makes me wish there were types (er, sorry, me

Re: possible side-effect/problem in http://clojure.org/concurrent_programming

2013-06-14 Thread Amir Wasim
complete example (ns wm.test (import [java.util.concurrent Executors]) ) (def deliveries (map char (range 65 90))) (defn- test-fn [delivery another param] (println "in test sleeping" delivery another param) (let[sleep-for (rand-int 1)] (println "sleeping for " sleep-for) (T

possible side-effect/problem in http://clojure.org/concurrent_programming

2013-06-14 Thread Amir Wasim
I was using the first example to make a process executing parallely (defn test-stm [nitems nthreads niters] (let [refs (map ref (repeat nitems 0)) pool (Executors/newFixedThreadPool nthreads) tasks (map (fn [t] (fn [] (dotimes [n n