On Dec 5, 8:24 am, Rich Hickey <[EMAIL PROTECTED]> wrote: > On Dec 5, 5:51 am, bOR_ <[EMAIL PROTECTED]> wrote: > > > Are there any screencasts planned which will feature atoms? (I found > > that the screencasts are an excellent way of learning clojure). > > Screencasts are generally a side-effect of a speaking engagement. I > imagine next time I give a talk, I'll talk about atoms too. > > To address the general question about when to use atoms/refs/agents, > it helps to think of things this way: > > First, note that in talking about atoms/refs/agents we are talking > about Clojure's reference types that allow changes to be seen by > multiple threads, so these three reference types are all shared > reference types. > > There are two dimensions to the choice about using them, the first is > - will the changes be synchronous or asynchronous, and the second is, > will a change to this reference ever need to be coordinated with a > change to another reference or references. > > Chouser made a nice diagram after I described this on IRC: > > http://clojure.googlegroups.com/web/clojure-conc.png > > As you can see, for coordinated changes, refs + transactions are the > only game in town, and asynchrony (beyond a set of commutes) doesn't > make much sense, so no reference type is coming to replace the X. > > For independent change, you have two choices, agents and atoms. > > Atoms are synchronous, the change happens on the calling thread. They > are as close to a plain variable as you get from Clojure, with a > critical benefit - they are thread safe, in particular, they are not > subject to read-modify-write race conditions. Your writes don't happen > unless they are a function of what was read. But modifications to > atoms are side effects, and thus need to be avoided in transactions. > Julian's post highlighted a point I need to make clear about the above: "Modifications to atoms are side effects, and thus need to be avoided in transactions" should be qualified with: "unless you are ok with having them run more than once. For many intended uses of atoms, like memoization caches, that's perfectly fine." Rich --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---