private static void QueueTest() { Console.WriteLine("QueueTest:"); var buffer = new STM.Collections.Queue <int>(); var t1 = new Thread(() => { var sw = Stopwatch.StartNew(); for (var i = 0; i < 1000; i++) { Console.WriteLine(buffer.Dequeue()); Console.WriteLine("Index :" + i); } sw.Stop(); Console.WriteLine("Milisecs: " + sw.ElapsedMilliseconds); }); var t2 = new Thread(() => { for (var i = 0; i < 1000; i++) { buffer.Enqueue(i); } }); t1.Start(); t2.Start(); t1.Join(); t2.Join(); }
public static void NestingExample() { TMVar <string> s = new TMVar <string>(string.Empty); var result = STMSystem.Atomic(() => { s.Value = "abc"; STMSystem.Atomic(() => { s.Value = s + "def"; }); return(s.Value); }); STM.Collections.Queue <Person> buffer1 = new STM.Collections.Queue <Person>(); STM.Collections.Queue <Person> buffer2 = new STM.Collections.Queue <Person>(); STMSystem.Atomic(() => { var item = buffer1.Dequeue(); buffer2.Enqueue(item); }); }