Best way to test retry

18 views
Skip to first unread message

Hanns Holger Rutz

unread,
Mar 15, 2014, 7:01:02 AM3/15/14
to scala-stm-e...@googlegroups.com
Hi there,

I have a suspicion that some code of mine performs side effects which
shouldn't happen within a Txn. Therefore, I want to deliberately run a
Txn multiple times retried. Like this:

var retries = 3
atomic { implicit tx =>
doSomething()
if (retries > 0) {
retries -= 1
Txn.retry
}
}

But this hangs because `Txn.retry` waits until "some memory location
observed by this transaction has been changed".

What would be the best way to issue the retry explicitly? How would I
cause Txn.retry to unhang?

Thanks, .h.h.

Hanns Holger Rutz

unread,
Mar 15, 2014, 7:07:08 AM3/15/14
to scala-stm-e...@googlegroups.com
Here's my idea:

val retries = Ref(3)
atomic { implicit tx =>
doSomething()
if (retries() > 0) {
new Thread {
override def run(): Unit = {
println("retrying...")
retries.single -= 1
}
start()
}
Txn.retry
}
}

Correct?

Nathan Bronson

unread,
Mar 15, 2014, 10:19:23 PM3/15/14
to scala-stm-e...@googlegroups.com
I suggest Txn.retryFor(1, TimeUnit.NANOSECONDS). The first time it is encountered it will act like retry(), but after it has waited 1 nanosecond for another transaction to touch its read set it will try again. The second time it is encountered this call will be a no-op, because there has already been >= 1 ns of top-level blocking.

 - Nathan


--

---
You received this message because you are subscribed to the Google Groups "Scala STM Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-stm-expert-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Nathan Grasso Bronson
ngbr...@gmail.com
Reply all
Reply to author
Forward
0 new messages