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 niters]
(dosync
(doseq [r refs]
(alter r + 1 t))))))
(range nthreads))]
(doseq [future (.invokeAll pool tasks)]
(.get future))
(.shutdown pool)
(map deref refs)))
i was generating taks just like above as follows
tasks (map #(test-fn % 1 5) deliveries)
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
I tried with the following
tasks (for [delivery_ deliveries] #(test-fn delivery_ 1 5))
and it works and 4 threads are active during execution.
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.