On Tue, Sep 22, 2009 at 3:18 PM, Roger Gilliar <ro...@gilliar.de> wrote: > >> thanks a lot. Your code looks much better than mine. But there is one >> part that I don't understand: >> >> (defn producer [] >> (if (dosync (if (not @consuming) >> (alter data conj 1))) >> (recur))) >> > After rereading the docs several times It seems that I begin to > understand how this works. The values of the vars inside a dosync > block are determined when the dosync block starts. This makes it > impossible that @consuming changes after the dosync block is entered. > > True ?
No, that's not true. consuming is a Ref. Refs maintain a chain of their historical values. Inside a transaction when the value of a Ref is needed, the Ref finds its newest value in the chain that was set before the transaction started. So it doesn't have to do this when the transaction starts. It waits until the value is actually needed. For more details on this, see http://ociweb.com/mark/stm/article.html. -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---