This page summarizes some of Clojure's key concepts regarding references (etc).
It also provides links to more detailed information.
Clojure provides several "safe" ways to change data
in the face of concurrent access (eg, by multiple threads).
allow independent, asynchronous changes to individual locations.
The caller places an action (a "pure" function with optional arguments)
on the location's queue.
The caller may then proceed or wait, as appropriate.
At some point in the future,
the location's agent will (attempt to) perform the action.
provide a way to manage shared, synchronous, independent state.
Like an Agent, an Atom is changed by the application of a "pure" function.
However, any change will occur immediately (if ever).
Refs and STM
allow safe shared use of mutable storage locations,
by means of a built-in
Software Transactional Memory
As discussed above
data access in an STM transaction is guaranteed to be
Each Ref points to a particular value, as of an instant in time.
A Ref to the same object, taken later in time, may have a different value.
However, each Ref's target object is guaranteed to remain unchanged.
Access is performed in an optimistic, speculative manner;
if a conflict occurs, the "losing" access simply retries.
provide a mechanism
to bind (and dynamically rebind) symbols (etc) to different values.
Because the binding is thread-local and obeys a stack discipline,
Vars are safe to use in concurrent programs.
This wiki page is maintained by Rich Morin
an independent consultant specializing in software design, development, and documentation.
Please feel free to email
comments, inquiries, suggestions, etc!