Concurrency
Atom
- An
atom
can be modified
- Although they can be modified, they are
thread-safe
- The value of an atom can be accessed with
@
Swap
- The
swap!
function changes the value of an atom
- All other function that modifies an atom must have
!
in its name
- Functions that modify the value of atom are functions with
side effects
Retry
- If an atom changes while a function that accesses it is running, this function is
rerun
- Also before updating an atom (swap), it is checked whether the atom has been changed before. If yes, the whole function is rerun
- The
retry function
must be as simple as possible!
- Therefore, functions that access an atom are performed as a
transaction
- The retry mechanism is implemented instead of using traditional
locks
Reference
- Differs from an atom in a way that it
allows transactions with multiple mutable elements
- The atom itself do not allow changes from multiple atoms in the same function
- Perform changes with the help of
transactions
with the function dosync
.
- All operations inside a transaction are performed together, or none of them is performed
Future
- Returns a
promise
of a result in the future
- Futures are executed in a
parallel thread
and do not block the current thread!
- Futures can
resolve
or fail