On Tuesday, June 9, 2015 at 4:24:16 PM UTC-4, Michael Gardner wrote: > > Thanks. That does appear to provide the guarantee I was looking for. > > > On Jun 9, 2015, at 12:14 PM, Andy Fingerhut <andy.fi...@gmail.com > <javascript:>> wrote: > > > > swap! is implemented using Java's AtomicReference class and its > compareAndSet method. I haven't dug into the Java source code implementing > that class, but you can read the Java documentation for all Atomic* Java > classes here: > > > > > https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/package-summary.html > > > > > The summary there is that all accesses to Atomic* classes should have > similar memory model guarantees as Java fields declared volatile. I don't > have a good authoritative link handy for Java documentation on volatile, > but the basic idea is that they should not be cached locally by individual > threads, but be visible to all. >
My own recollection jibes with this: atom changes are memory-barriered. OTOH, if the atom is swap!ped concurrently by other threads, all bets are off. Some other thread might dec it in between your thread's inc and dec of it. If you need to guard against that as well, then you need refs and dosync and to inc and then dec within a transaction. Then the whole sequence of events of "... inc ... dec ..." becomes atomic from the perspective of other threads, and not just the inc and the dec, separately. -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.