Created
August 13, 2014 18:17
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
import scala.concurrent.stm._ | |
object Test { | |
def run(n: Int) = { | |
val x = Ref(0) | |
val y = Ref(0) | |
(1 to n) foreach { i => | |
atomic { implicit tx => | |
val x1 = x() | |
val y1 = y() | |
if (x() != y()) retry | |
x() = x1 + 1 | |
y() = y1 + 1 | |
} | |
} | |
} | |
def time(block: => Unit) = { | |
val beginTime=System.currentTimeMillis | |
block | |
val endTime=System.currentTimeMillis | |
println(endTime-beginTime) | |
} | |
time(run(1000000)) | |
} | |
// scala> time(run(1000000)) | |
// 401 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment