No, it means exactly the same thing as volatile in Java (and is implemented in the Volatile Java class which holds a single volatile field). Basically a "volatile box" since a field must exist inside a class. The semantics are the same as Java - writes are guaranteed to be seen by subsequent reads on any thread (that property is not guaranteed by a non-volatile field).
vswap! on a volatile is syntactically similar to swap! on an atom but without the atomicity guarantees. That is, vswap! consists of a read followed by a write but this is non-transactional so another thread could change the value in between. In other words: don't use this unless you can enforce thread isolation or safety through other means. Thus, volatiles are dangerous *by default*, unlike every other stateful thing in Clojure. Some stateful transducers use volatiles for performance and provide thread isolation via how they are constructed and used. On Tuesday, September 9, 2014 12:06:36 PM UTC-5, Luc wrote: > > The keyword has different meaning > depending on the language and > context. > > Most of the time to prevent optimizations by the compiler to insure write > ordering > and some consistent view (Java use). > > Not here. It's meant to warn that > nothing is guaranteed, no synchronization, no consistent view. > > It should be kept local (no leak > outside of a narrow scope) and > certainly not shared > by multiple threads. > > Luc P. > > > > Excuse my ignorance but does "volatile!" have anything to do with Java's > > "volatile" keyword? Is there any relation at all? I'm not suggesting a > name > > change, but it can be confusing coming from that angle. Maybe a blurb in > > the doc string? > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clo...@googlegroups.com > <javascript:> > > Note that posts from new members are moderated - please be patient with > your first post. > > To unsubscribe from this group, send email to > > clojure+u...@googlegroups.com <javascript:> > > 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+u...@googlegroups.com <javascript:>. > > For more options, visit https://groups.google.com/d/optout. > > > -- > Luc Prefontaine<lprefo...@softaddicts.ca <javascript:>> sent by ibisMail! > -- 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.