changeset 108:f3bdb7ba59b9 v2

sync
author cin
date Tue, 11 Nov 2014 18:37:35 +0300
parents f5220e5472ef
children 1b7ebcc52e5a
files MonoPlay/Program.cs
diffstat 1 files changed, 36 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/MonoPlay/Program.cs	Tue Nov 11 04:14:21 2014 +0300
+++ b/MonoPlay/Program.cs	Tue Nov 11 18:37:35 2014 +0300
@@ -16,10 +16,23 @@
 
             const int count = 10000000;
 
+
             var t1 = Environment.TickCount;
 
-            for (var i = 0; i < count; i++)
-                q1.Enqueue(i);
+            Promise<int>.CreateComposite(
+                new [] {
+                    AsyncPool.InvokeNewThread(() => {
+                        for (var i = 0; i < count; i++)
+                            q1.Enqueue(i);
+                    }),
+                    AsyncPool.InvokeNewThread(() => {
+                        int temp = 0;
+                        for(int i =0 ; i< count ; i++)
+                            while(!q1.TryDequeue(out temp)){
+                            }
+                    })
+                }
+            ).Join();
 
             var t2 = Environment.TickCount;
             Console.WriteLine("MTQueue: {0} ms", t2 - t1);
@@ -36,9 +49,27 @@
 
             t1 = Environment.TickCount;
 
-            for (var i = 0; i < count; i++)
-                lock (q2)
-                    q2.Enqueue(i);
+            Promise<int>.CreateComposite(
+                new [] {
+                    AsyncPool.InvokeNewThread(() => {
+                        for (var i = 0; i < count; i++)
+                            lock (q2)
+                                q2.Enqueue(i);
+                    }),
+                    AsyncPool.InvokeNewThread(() => {
+                        for(int i = 0 ; i< count ;)
+                            lock(q2) {
+                                if(q2.Count == 0)
+                                    continue;
+                                q2.Dequeue();
+                                i++;
+                            }
+
+                    })
+                }
+            ).Join();
+
+
 
             t2 = Environment.TickCount;
             Console.WriteLine("LinkedList+Lock: {0} ms", t2 - t1);