Hi,

I wrote this script:

(def number (ref 0))
(def add1 (partial + 1))
(def num-threads (Integer/parseInt (first *command-line-args*)))
(def increments (Integer/parseInt (second *command-line-args*)))

(defn add-number [field times]
  (dorun (repeatedly times
              (fn []
                (dosync
                  (alter field add1))))))

(def thread (partial add-number number increments))

(printf "Starting %d threads, each with %d increments\n"
        num-threads increments)
(dorun (apply pcalls (repeat num-threads thread)))
(printf "Number = %d\n" @number)

It is basically a port of a C code that I wrote to demonstrate STM. The
problem is when I run it, it displays

% java -cp /usr/share/clojure/clojure.jar clojure.main fixed.clj 5 1000
Starting 5 threads, each with 1000 increments
Number = 5000

And instead of exiting, it "hangs" in this state for a number of
seconds before finally quitting. Why is that so and how can I fix that?

I tried calling (System/exit 0) in the end, but then it didn't even
display anything before quitting.

Hope to get some answers. Clojures lazy evaluation sometimes confuses
me.

regards,
Marek

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

Reply via email to