8

I would like to analyze the behavior of a Clojure program versus a locking version in C. One metric I would like to track is the total number of aborted transactions for my Clojure program.

The only problem is that I can't mutate a variable outside of the context of the transaction that I am in. What I'm trying to do is this:

(dosync
(try
  (alter my_num inc)
  (catch Throwable t
    (do
      (alter total_aborts inc)
      (println "Caught " (.getClass t))
      (throw t)))))

Of course, total_aborts will never get incremented if the transaction doesn't finish!!! So how can I do this? Thanks!

Timoteo
  • 259
  • 3
  • 10
  • http://stackoverflow.com/questions/4792197/how-can-i-see-the-number-of-rollbacks-in-my-stm-in-clojure – Gene T Feb 03 '12 at 04:47

1 Answers1

6

You can make my-num and total-aborts atoms and use swap! instead of alter.

Matthias Benkard
  • 15,497
  • 4
  • 39
  • 47