Tag: stm

Clojure STM(dosync)x Java同步块

Clojure STM(dosync)方法和Java同步Block有什么区别? 我正在阅读“睡觉的理发师”问题下面的代码。 ( http://www.bestinclass.dk/index.clj/2009/09/scala-vs-clojure-round-2-concurrency.html ) (defn the-shop [a] (print “[k] entering shop” a) (dosync (if (< (count @queue) seats) (alter queue conj a) (print "[s] turning away customer" a)))) 为了避免竞争条件,使用dosync ,所以我问自己“Java同步块有什么区别(STM)”? 它会阻止这个关键代码吗? 提前致谢 ! 丹塔斯