compare-and-set!

clojure.core

  • (compare-and-set! atom oldval newval)
Atomically sets the value of atom to newval if and only if the
current value of the atom is identical to oldval. Returns true if
set happened, else false

1 Example top

  • user=> (def a (atom 0))
    #'user/a
    user=> (compare-and-set! a 10 20)
    false
    user=> @a
    0
    user=> (compare-and-set! a 0 10)
    true
    user=> @a
    10
    
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/core.clj:2111 top

(defn compare-and-set!
  "Atomically sets the value of atom to newval if and only if the
  current value of the atom is identical to oldval. Returns true if
  set happened, else false"
  {:added "1.0"
   :static true}
  [^clojure.lang.Atom atom oldval newval] (.compareAndSet atom oldval newval))
Vars in clojure.core/compare-and-set!:
Used in 0 other vars

Comments top

No comments for compare-and-set!. Log in to add a comment.