Skip to content

Instantly share code, notes, and snippets.

@Sciss
Created April 12, 2018 08:47
Show Gist options
  • Save Sciss/942b6caf70d2732942204391b9727fb6 to your computer and use it in GitHub Desktop.
Save Sciss/942b6caf70d2732942204391b9727fb6 to your computer and use it in GitHub Desktop.
package foo
import scala.concurrent.stm._
object Test {
def main(args: Array[String]): Unit = {
var b = true
atomic { implicit tx =>
println("atomic")
test() {
println(s"b = $b")
if (b) {
b = false
Txn.retryFor(1000)
}
}
}
sys.exit()
}
val ref = Ref(0)
def test[A]()(thunk: => A)(implicit tx: InTxn): A = {
val old = ref.swap(1)
try {
thunk
} finally {
ref() = old // seems this is fine even during roll-back
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment