private Thread CreatePhilosopher(VBox <int> eatCounter, Fork left, Fork right) { var t1 = new Thread(() => { while (JVSTMSystem.Atomic((t) => eatCounter.Read(t) < MAX_EAT_COUNT)) { JVSTMSystem.Atomic((t) => { if (!left.State.Read(t) || !right.State.Read(t)) { JVSTMSystem.Retry(); } left.State.Put(t, false); right.State.Put(t, false); }); Thread.Sleep(100); JVSTMSystem.Atomic((t) => { eatCounter.Put(t, eatCounter.Read(t) + 1); }); JVSTMSystem.Atomic((t) => { left.State.Put(t, true); right.State.Put(t, true); }); Thread.Sleep(100); } }); return(t1); }
public void JVNestingOrElseTest3() { var tm1 = new VBox <int>(1); var tm2 = new VBox <int>(2); JVSTMSystem.Atomic((t) => { tm1.Put(t, 10);; JVSTMSystem.Atomic((t2) => { if (tm1.Read(t2) == 10) { JVSTMSystem.Retry(); } tm1.Put(t2, 20); }, (t3) => { tm1.Put(t3, 50); }); var temp = tm1.Read(t); tm2.Put(t, temp * temp); }); var result = JVSTMSystem.Atomic(t => tm2.Read(t)); Assert.AreEqual(2500, result); }
public void AttemptToPickUp(JVTransaction t) { if (!State.Read(t)) { JVSTMSystem.Retry(); } State.Put(t, false); }
public T Dequeue() { return(JVSTMSystem.Atomic((t) => { var node = _head.Read(t).Next.Read(t); if (node == null) { JVSTMSystem.Retry(); } _head.Put(t, node); return node.Value; })); }