Skip to content

Instantly share code, notes, and snippets.

/post.scala
Created Jul 20, 2017

Embed
What would you like to do?
the description for this gist
class LockFreeRook extends Rook {
private var coordinates = new AtomicReference[(Long, Long)]((0,0))
@tailrec
final def updatePosition(offset: (Long, Long)): Unit = {
val prev = coordinates.get()
val updated = (prev._1 + offset._1, prev._2 + offset._2)
if (!coordinates.compareAndSet(prev, updated)) {
updatePosition(offset)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.