Thanks for help. I have just used synchronization mechanizm from Java.
Here is a code:





monitor.clj


(ns michael.ds.monitor
        (:import [java.util.concurrent.locks ReentrantLock Condition ]))


(defn create-monitor[]
        (ReentrantLock.))

(defn create-cond[m]
        (.newCondition m))

(defmacro lock-monitor[ lck & body ]
        `(let [z# ~lck]
        (try (.lock z#)
                ~...@body
                 (finally (.unlock z#)))))

(defn signal-cond[ c ]
        (.signal c))

(defn wait-cond[c]
        (.await c))



factory.clj


(ns michael.ds.factory
  (:require [clojure.set])
        (:use [michael.ds commons monitor]))

(def data (atom ...))

(def my-monitor (create-monitor))

(def my-cond (create-cond my-monitor))


(defn produce[ ...]
        (lock-monitor my-monitor
        (swap! data ... )
                (signal-cond my-cond)))

(defn consume[...]
        (with-local-vars [r nil]
                (while (nil? @r)
                (lock-monitor my-monitor
                (swap! data (fn[ a ]

                                ...
                                (if ...(wait-cond my-cond))
                                ...


                ))))@r))






I have dotted negligible code.
Let me know if it can be simplicified or I have error in assumption.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to