Last active
December 24, 2015 23:49
-
-
Save paulk-asert/6882702 to your computer and use it in GitHub Desktop.
This file contains 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
@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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Groovy version of https://gist.github.com/anonymous/2516410
You could of course keep more of the variable typing information if you wanted.