public static void Run() { var m1 = ClassicMailbox.AsLock((string msg) => { //Console.WriteLine(String.Format("[dst:{0}]{1}", Thread.CurrentThread.ManagedThreadId, msg)); }); var result = InstrumentedOperation.Test(() => { for (int i = 0; i < SIZE; ++i) { m1.Send(String.Format("[src:{0}] Message #{1}", Thread.CurrentThread.ManagedThreadId, i + 1)); } m1.CancelAndWait(); }, "Queue<T> and lock with signaling", SIZE); var m2 = ClassicMailbox.AsLockFree((string msg) => { //Console.WriteLine(String.Format("[dst:{0}]{1}", Thread.CurrentThread.ManagedThreadId, msg)); }); result = InstrumentedOperation.Test(() => { for (int i = 0; i < SIZE; ++i) { m2.Send(String.Format("[src:{0}] Message #{1}", Thread.CurrentThread.ManagedThreadId, i + 1)); } m2.CancelAndWait(); }, "BlockingCollection<T> and lock free queue", SIZE); }
//const int SIZE = 100000; //const int SIZE = 10000; //const int SIZE = 1000; //const int SIZE = 10; public static void RunTypeMsg() { var m = ClassicMailbox.AsLockFree((string msg) => { //Console.WriteLine(String.Format("\n\t[dst:{0}]{1}", Thread.CurrentThread.ManagedThreadId, msg)); }); string line; while ((line = ConsoleEx.ReadLn("Type msg or ENTER to exit: ")) != String.Empty) { m.Send(String.Format("[src:{0}] = {1}", Thread.CurrentThread.ManagedThreadId, line)); } m.CancelAndWait(); Console.WriteLine("[src:{0}] = Mailbox stopped...", Thread.CurrentThread.ManagedThreadId); }