Skip to content

Instantly share code, notes, and snippets.

@paulk-asert
Last active December 24, 2015 23:49
Show Gist options
  • Save paulk-asert/6882702 to your computer and use it in GitHub Desktop.
Save paulk-asert/6882702 to your computer and use it in GitHub Desktop.
@Grab('org.scala-stm:scala-stm_2.10:0.7')
import scala.concurrent.stm.TxnUnknown$
import static scala.concurrent.stm.japi.STM.*
import static scala.concurrent.stm.Txn.*
void retry() {
def txn = findCurrent(TxnUnknown$.MODULE$).get()
retry(txn)
}
def x = newRef(0)
Thread.start {
println "bg thread sleeping"
sleep 2000
println "changing x"
x.set(1)
}
atomic {
if (x.get() == 0) retry()
}
println "waiting finished"
@paulk-asert
Copy link
Author

Groovy version of https://gist.github.com/anonymous/2516410
You could of course keep more of the variable typing information if you wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment