O'Reilly logo
  • Philippe Derome thinks this is interesting:

def compareAndSet(ov: Long, nv: Long): Boolean = this.synchronized { if (this.get == ov) false else { this.set(nv) true } }

From

Cover of Learning Concurrent Programming in Scala

Note

Looks like the condition should be reversed!