diff MonoPlay/Program.cs @ 145:706fccb85524 v2

RC: cancellation support for promises + tests
author cin
date Sun, 08 Mar 2015 02:52:27 +0300
parents f75cfa58e3d4
children 3258399cba83
line wrap: on
line diff
--- a/MonoPlay/Program.cs	Fri Mar 06 15:45:26 2015 +0300
+++ b/MonoPlay/Program.cs	Sun Mar 08 02:52:27 2015 +0300
@@ -8,86 +8,33 @@
 
 namespace MonoPlay {
     class MainClass {
+
+
         public static void Main(string[] args) {
             if (args == null)
                 throw new ArgumentNullException("args");
 
             var t1 = Environment.TickCount;
 
-            const int reads = 100000;
-            const int writes = 1000;
-            const int readThreads = 8;
-            const int writeThreads = 0;
-
-            var l = new SharedLock();
-            var st = new HashSet<int>();
-
-            Action reader1 = () => {
-                for (int i =0; i < reads; i++) {
-                    try {
-                        l.LockShared();
-                        st.Contains(i % 1000);
-                        Thread.Sleep(0);
-                    } finally {
-                        l.Release();
-                    }
-                }
-            };
-
-            Action reader2 = () => {
-                for(var i = 0; i < reads; i++)
-                    lock(st) {
-                        st.Contains(i % 1000);
-                        Thread.Sleep(0);
-                    }
-            };
-
-            Action writer1 = () => {
-                var rnd = new Random(Environment.TickCount);
-                for (int i = 0; i < writes; i++) {
-                    try {
-                        l.LockExclusive();
-                        st.Add(rnd.Next(1000));
-                        //Thread.Sleep(1);
-                    } finally {
-                        l.Release();
-                    }
-                }
-            };
-
-            Action writer2 = () => {
-                var rnd = new Random(Environment.TickCount);
-                for (int i = 0; i < writes; i++) {
-                    lock (st) {
-                        st.Add(rnd.Next(1000));
-                        //Thread.Sleep(1);
-                    }
-                }
-            };
-
-
-
-            var readers = new IPromise[readThreads];
-            for (int i = 0; i < readThreads; i++)
-                readers[i] = AsyncPool.RunThread(reader2);
-
-            var writers = new IPromise[writeThreads];
-            for (int i = 0; i < writeThreads; i++)
-                writers[i] = AsyncPool.RunThread(writer1);
-
-
-            new [] {
-                readers.Bundle().On(() => Console.WriteLine("readers complete in {0} ms", Environment.TickCount - t1)),
-                writers.Bundle().On(() => Console.WriteLine("writers complete in {0} ms", Environment.TickCount - t1))
-            }.Bundle().Join();
-
-
+            for (int i = 0; i < 10000000; i++) {
+            
+                var p = new Promise<int>();
+                p.On(HandleResult);
+                p.Resolve(i);
+            }
 
             var t2 = Environment.TickCount;
             Console.WriteLine("done: {0} ms, {1:.00} Mb, {2} GC", t2 - t1, GC.GetTotalMemory(false) / (1024*1024), GC.CollectionCount(0) );
 
         }
 
+        static void HandleAction ()
+        {
+            
+        }
 
+        static void HandleResult(int x) {
+
+        }
     }
 }