;; A lightweight (but low level) syncrhonization solution with volatile!
;; Prefer promise/deliver for this (unless you know what you're doing).
;; vars/atoms is also possible but they're heavier
;; (locking and CAS respectively).
(def ready (volatile! false))
(def result (volatile! nil))
(defn start-consumer []
(future
(while (not @ready) ; consumer starts spinning
(Thread/yield)) ; release control for other threads
(println "Consumer getting result:" @result)))
(defn start-producer []
(future
(vreset! result :done) ; change the 1st volatile, no reordering (guaranteed).
(vreset! ready true))) ; change the ready state.
(start-consumer)
(start-producer)
;; Consumer getting result: :done