Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Transactions 计算Clojure中中止的事务_Transactions_Clojure_Functional Programming - Fatal编程技术网

Transactions 计算Clojure中中止的事务

Transactions 计算Clojure中中止的事务,transactions,clojure,functional-programming,Transactions,Clojure,Functional Programming,我想分析Clojure程序与C中锁定版本的行为。我想跟踪的一个指标是Clojure程序中止事务的总数 唯一的问题是我不能在我所处的事务上下文之外变异变量。我想做的是: (dosync (try (alter my_num inc) (catch Throwable t (do (alter total_aborts inc) (println "Caught " (.getClass t)) (throw t))))) 当然,如果事务没有完成

我想分析Clojure程序与C中锁定版本的行为。我想跟踪的一个指标是Clojure程序中止事务的总数

唯一的问题是我不能在我所处的事务上下文之外变异变量。我想做的是:

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

当然,如果事务没有完成,那么total_aborts将永远不会增加!!!那我该怎么做呢?谢谢

您可以进行
my num
total中止
并使用
swap而不是
alter

谢谢!我忘记了原子。