title: Counting aborted transactions in Clojure
body: <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>(dosync
  (try
    (alter my_num inc)
    (catch Throwable t
      (do
        (alter total_aborts inc)
        (println "Caught " (.getClass t))
        (throw t)))))
  </code></pre>
  
  <p>Of course, total_aborts will never get incremented if the transaction doesn't finish!!! So how can I do this? Thanks!</p>