Clojure's built-in STM cannot really include all the restrictions that you are looking for, because readers never wait for writers , and your requirements require readers to wait.
if you can forgive without blocking readers, then you can go ahead and
(. (java.lang.Thread. #(dosync (write stuff)) start)) (. (java.lang.Thread. #(dosync (read stuff)) start))
if you need readers to block, you will need another STM, there are many in the world.
source share