concurrency - 代理没有被执行

标签 concurrency clojure stm

我有一系列函数(如示例中的 some-operation),其中我 sendsend-off致代理商:

(defn some-operation [agent-state]
  (dosync
   (let [updated (foo agent-state)] ;; derive new state from old one
     (alter bar whatev updated) ;; reflect the new state in the world
     (send *agent* some-operation) ;; "recur"
     updated) ;; value for recur
   ))

(send (agent {}) some-operation)

在我开发应用程序时,这种方法对我有用。但是在代码库中进行了一些更改后,代理会在一段时间后停止运行(“一段时间”是几秒钟 - 几千个“递归”调用)。

他们的状态在域中有效,代理本身没有FAILED ,而且我确信他们不会在他们的 dosync 上活锁块( one can measure contention )。

我的怀疑是 JVM/OS 由于某种或其他原因阻止了底层执行程序线程运行。但我不知道如何检查这个假设是否正确。

一般来说,发送代理可能无法执行其挂起的“发送”的一些可能原因是什么?我可以检查/测量什么?

更新 - 给出以下调试修改...
(defn some-operation [agent-state]
  (let [f (future
            (dosync
             ...) ;; the whole operation, as per the previous example
            )]
    (Thread/sleep 1000) ;; give the operation some time
    (if (realized? f)
      @f

      ;; not realized: we deem the operation as blocking indefinetely
      (do
        (println :failed)
        (send *agent* some-operation)
        agent-state))))

...代理仍然卡住,甚至不打印 :failed .

最佳答案

值得留意的方式senddosync相互影响。所有调用 senddosync仅发生一次,并且仅在事务提交时发生 这可以防止将消息从稍后被丢弃的事务中传递给代理。您可以通过缩小 dosync 的范围来测试这一点。

关于concurrency - 代理没有被执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17270996/

相关文章:

Clojure STM 歧义因子

java - 为什么在while循环中等待Condition?

concurrency - Elixir - 受监督的进程似乎会阻止程序执行

clojure - 如何清楚地构建 core.async channel 之间的依赖关系?

clojure - 在集合上使用局部,减少-vs- apply

java - Clojure 银行账户汇款示例

java并发Future任务在发生任何异常时返回null并且不传播它

concurrency - 如何在Eclipse CDT中使用GCC/G++编译并运行C++0x?

clojure - 通过连接键来展平 map

Haskell: TVar: orElse