Skip to content
Snippets Groups Projects
Commit b1fcc592 authored by Régis Blanc's avatar Régis Blanc
Browse files

no dependency on leon List

parent d93606fa
No related branches found
No related tags found
No related merge requests found
...@@ -12,29 +12,32 @@ object DataRacing { ...@@ -12,29 +12,32 @@ object DataRacing {
implicit def toInstr(instr: (SharedState) => Unit): AtomicInstr = AtomicInstr(instr) implicit def toInstr(instr: (SharedState) => Unit): AtomicInstr = AtomicInstr(instr)
abstract class Runnable
case class RunnableCons(instr: AtomicInstr, tail: Runnable) extends Runnable
case class RunnableNil() extends Runnable
def execute(t1: List[AtomicInstr], t2: List[AtomicInstr], state: SharedState): Unit = (t1, t2) match { def execute(t1: Runnable, t2: Runnable, state: SharedState): Unit = (t1, t2) match {
case (x::xs, y::ys) => case (RunnableCons(x,xs), RunnableCons(y,ys)) =>
if(Random.nextBoolean) { if(Random.nextBoolean) {
x.instr(state) x.instr(state)
execute(xs, y::ys, state) execute(xs, RunnableCons(y,ys), state)
} else { } else {
y.instr(state) y.instr(state)
execute(x::xs, ys, state) execute(RunnableCons(x,xs), ys, state)
} }
case (Nil(), y::ys) => case (RunnableNil(), RunnableCons(y,ys)) =>
y.instr(state) y.instr(state)
execute(Nil(), ys, state) execute(RunnableNil(), ys, state)
case (x::xs, Nil()) => case (RunnableCons(x,xs), RunnableNil()) =>
x.instr(state) x.instr(state)
execute(xs, Nil(), state) execute(xs, RunnableNil(), state)
case (Nil(), Nil()) => () case (RunnableNil(), RunnableNil()) => ()
} }
def main(): Unit = { def main(): Unit = {
val state = SharedState(0) val state = SharedState(0)
val t1 = List[AtomicInstr]((s: SharedState) => s.i = s.i + 1) val t1 = RunnableCons((s: SharedState) => s.i = s.i + 1, RunnableNil())
val t2 = List[AtomicInstr]((s: SharedState) => s.i = s.i * 2) val t2 = RunnableCons((s: SharedState) => s.i = s.i * 2, RunnableNil())
execute(t1, t2, state) execute(t1, t2, state)
assert(state.i == 2) assert(state.i == 2)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment