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!
You can make my-num and total-aborts atoms and use swap! instead of alter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With