@Test public void libTxn_3() { Txn.executeRead( unit, () -> { assertEquals("In R, value()", 0, counter2.get()); assertEquals("In R, get()", 0, counter2.value()); }); Txn.executeWrite( unit, () -> { counter2.inc(); assertEquals("In W, value()", 0, counter2.value()); assertEquals("In W, get()", 1, counter2.get()); }); assertEquals("Direct value()", 1, counter2.value()); assertEquals("Direct get()", 1, counter2.get()); Txn.executeRead( unit, () -> { assertEquals("In R, value()", 1, counter2.get()); assertEquals("In R, get()", 1, counter2.value()); }); }
@Test public void libTxnThread_12() { long x1 = counter1.get(); ThreadTxn t = Txn.threadTxnRead( unit, () -> { long z1 = counter1.get(); assertEquals("Thread", x1, z1); }); Txn.executeWrite(unit, () -> counter1.inc()); t.run(); long x2 = counter1.get(); assertEquals("after", x1 + 1, x2); }
@Test public void libTxnThread_11() { long x1 = counter1.get(); Txn.executeWrite( unit, () -> { counter1.inc(); // Read the "before" state ThreadTxn t = Txn.threadTxnRead( unit, () -> { long z1 = counter1.get(); assertEquals("Thread read", x1, z1); }); counter1.inc(); t.run(); }); long x2 = counter1.get(); assertEquals("after", x1 + 2, x2); }