Created
April 12, 2018 08:47
-
-
Save Sciss/942b6caf70d2732942204391b9727fb6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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