title: What is the Scala equivalent of Clojure's Atom?
body: <p>Clojure <a href="http://clojure.org/atoms" rel="nofollow noreferrer">has an Atom</a> for <a href="http://clojure.org/concurrent_programming" rel="nofollow noreferrer">changing state between threads in a synchronous and independent manner</a>, <a href="https://stackoverflow.com/a/18976545/15441">that is not part of the STM</a>. You <a href="http://clojuredocs.org/clojure_core/clojure.core/atom" rel="nofollow noreferrer">use it like this</a>: </p>
  
  <pre><code>user=&gt; (def my-atom (atom 0))
  #'user/my-atom
  
  user=&gt; @my-atom
  0
  
  user=&gt; (swap! my-atom inc)
  1
  
  user=&gt; @my-atom
  1
  
  user=&gt; (swap! my-atom (fn [n] (* (+ n n) 2)))
  4
  </code></pre>
  
  <p>My question is: <strong>What is the Scala equivalent of Clojure's Atom?</strong></p>