Created
October 21, 2011 13:25
-
-
Save softprops/1303840 to your computer and use it in GitHub Desktop.
Stolen from the scala-user mailing list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Var[T](i: T) extends AtomicReference[T](i) { | |
def mutate(m: T => T): T = { | |
@tailrec def apply(): T = { | |
val c = get | |
val n = m(c) | |
if (compareAndSet(c, n)) n else apply() | |
} | |
apply() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment