I wrote a simple test to check it and it does not see reordering on
multiprocessing system. But it does not prove anything of course.
(def transaction-lock
(java.util.concurrent.locks.ReentrantLock.) )
(def transaction-counter (atom 0))
(def counting-agent (agent {:count 1}))
(defn check [agent-state transaction-id]
(if (not= (:count agent-state) transaction-id)
(throw (RuntimeException. "Reordering happened"))
(assoc agent-state :count (inc transaction-id)) ))
(defn work []
(locking transaction-lock
(let [
transaction-id (swap! transaction-counter inc)
]
(send counting-agent check transaction-id)
;(println (str transaction-id " id sent."))
)))
(defn workn [n]
(loop [cnt n]
(when (not (zero? cnt))
(work)
(recur (dec cnt)))))
(defn work10000 [] (workn 10000))
(.start (Thread. work10000))
(.start (Thread. work10000))
(.start (Thread. work10000))
(.start (Thread. work10000))
(.start (Thread. work10000))
(.start (Thread. work10000))
(.start (Thread. work10000))
(.start (Thread. work10000))
(.start (Thread. work10000))
(.start (Thread. work10000))
(workn 1)
--
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