This is some sort of repost from yesterday.  But I hope that this one  
describes my problem more precisely.
I have n threads that produce something. At some point in time a  
consumer starts and if the consumer starts, no more data should be  
produced.  Right now I can only come up with the following solution  
which I personally don't find very elegant.

Regards
   Roger

(def data (ref '()))

(def test-agent (agent '()))

(def processing-started (atom false))

(defn producer []
                (doseq [i (take 1000 (repeat 1))]
                        (await test-agent)
                        (dosync
                                (if (= @processing-started false)
                                        (do
                                                (alter data conj i))))))
                        
        
(defn IsTrue [d] true)
        
(defn setme [agent]
        (loop []
                (let[x1 (count @data)]
                        (. Thread (sleep 1500))
                        (let [x2 (count @data)]
                                (if (not= x1 x2)
                                        (recur)
                                        (dosync
                                                (swap! processing-started 
IsTrue)
                                                (println "doesn't change 
anymore")
                                                (println (count @data))
                                                (. Thread (sleep 1500))
                                                (println (count @data))         
                                        (ref-set data '())))))))


(defn consumer []
        (. Thread (sleep 350))
        (send-off test-agent setme))
                                                
(dorun (apply pcalls (conj (take 200 (repeat producer)) consumer)))

(shutdown-agents)

(println @data)

--~--~---------~--~----~------------~-------~--~----~
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