Code:
object Blub {
import scala.concurrent.stm._
val last = Ref("none")
def bla() = atomic { implicit txn =>
last() = "outer"
try {
atomic { implicit txn =>
last() = "inner"
println(last())
throw new RuntimeException
}
} catch {
case _: RuntimeException =>
}
}
def main(args: Array[String]): Unit = {
bla()
println("Result: "+last.single())
}
}
Output:
inner
inner
Result: outer
Can anyone explain why the inner atomic block is run twice? I know that it does a rollback due to the exception, hence the final result. But i don't understand the why it runs the code for a second time.