private Thread CreatePhilosopher(TMInt eatCounter, TMVar <bool> left, TMVar <bool> right) { var t1 = new Thread(() => { while (eatCounter < MAX_EAT_COUNT) { STMSystem.Atomic(() => { if (!left || !right) { STMSystem.Retry(); } left.Value = false; right.Value = false; }); Thread.Sleep(100); ++eatCounter; STMSystem.Atomic(() => { left.Value = true; right.Value = true; }); Thread.Sleep(100); } }); return(t1); }
public void ExceptionInTransaction() { TMInt i = new TMInt(0); TMInt j = new TMInt(0); STMSystem.Atomic(() => { i.Value = 1; throw new InvalidOperationException(); j.Value = 1; }); }
public void Setup() { var eatCounter = new TMInt(0); var fork1 = new TMVar <bool>(true); var fork2 = new TMVar <bool>(true); var fork3 = new TMVar <bool>(true); var fork4 = new TMVar <bool>(true); var fork5 = new TMVar <bool>(true); t1 = CreatePhilosopher(eatCounter, fork1, fork2); t2 = CreatePhilosopher(eatCounter, fork2, fork3); t3 = CreatePhilosopher(eatCounter, fork3, fork4); t4 = CreatePhilosopher(eatCounter, fork4, fork5); t5 = CreatePhilosopher(eatCounter, fork5, fork1); }
public static void TMVarExample() { TMVar <string> tmString = new TMVar <string>("abc"); TMVar <bool> tmBool = new TMVar <bool>(); TMVar <Person> tmPerson = new TMVar <Person>(new Person("Bo Hansen", 57)); TMInt tmInt = new TMInt(12); STMSystem.Atomic(() => { if (tmBool && tmString == "abc") { tmInt++; } }); }
public void ExceptionInTransaction2() { TMInt i = new TMInt(0); TMInt j = new TMInt(0); try { STMSystem.Atomic(() => { i.Value = 1; throw new InvalidOperationException(); j.Value = 1; }); } catch (InvalidOperationException) { } Assert.AreEqual(1, i.Value); Assert.AreEqual(0, j.Value); }
public void Setup() { _tmInt = new TMInt(5); }