annotate Implab.Test/AsyncTests.cs @ 76:c761fc982e1d v2

Refactoring of the IPromise<T> interface Added tests
author cin
date Wed, 10 Sep 2014 17:53:05 +0400
parents 3b8393be3441
children 91362ffbecf8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
1 using System;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
2 using Microsoft.VisualStudio.TestTools.UnitTesting;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
3 using System.Reflection;
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
4 using System.Threading;
11
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
5 using Implab.Parallels;
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
6
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
7 namespace Implab.Test {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
8 [TestClass]
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
9 public class AsyncTests {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
10 [TestMethod]
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
11 public void ResolveTest() {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
12 int res = -1;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
13 var p = new Promise<int>();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
14 p.Then(x => res = x);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
15 p.Resolve(100);
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
16
19
e3935fdf59a2 Promise is rewritten to use interlocked operations instead of locks
cin
parents: 17
diff changeset
17 Assert.AreEqual(100, res);
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
18 }
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
19
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
20 [TestMethod]
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
21 public void RejectTest() {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
22 int res = -1;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
23 Exception err = null;
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
24
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
25 var p = new Promise<int>();
73
3b8393be3441 fixed tests
cin
parents: 34
diff changeset
26 p.Then(
3b8393be3441 fixed tests
cin
parents: 34
diff changeset
27 x => res = x,
3b8393be3441 fixed tests
cin
parents: 34
diff changeset
28 e => {
3b8393be3441 fixed tests
cin
parents: 34
diff changeset
29 err = e;
3b8393be3441 fixed tests
cin
parents: 34
diff changeset
30 return -2;
3b8393be3441 fixed tests
cin
parents: 34
diff changeset
31 }
3b8393be3441 fixed tests
cin
parents: 34
diff changeset
32 );
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
33 p.Reject(new ApplicationException("error"));
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
34
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
35 Assert.AreEqual(res, -1);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
36 Assert.AreEqual(err.Message, "error");
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
37
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
38 }
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
39
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
40 [TestMethod]
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
41 public void CancelExceptionTest() {
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
42 var p = new Promise<bool>();
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
43 p.Cancel();
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
44
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
45 var p2 = p.Cancelled(() => {
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
46 throw new ApplicationException("CANCELLED");
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
47 });
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
48
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
49 try {
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
50 p2.Join();
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
51 Assert.Fail();
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
52 } catch (ApplicationException err) {
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
53 Assert.AreEqual("CANCELLED", err.InnerException.Message);
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
54 }
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
55
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
56 }
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
57
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
58 [TestMethod]
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
59 public void ContinueOnCancelTest() {
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
60 var p = new Promise<bool>();
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
61 p.Cancel();
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
62
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
63 var p2 = p
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
64 .Cancelled(() => {
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
65 throw new ApplicationException("CANCELLED");
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
66 })
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
67 .Error(e => true);
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
68
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
69 Assert.AreEqual(true, p2.Join());
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
70 }
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
71
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
72 [TestMethod]
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
73 public void JoinSuccessTest() {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
74 var p = new Promise<int>();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
75 p.Resolve(100);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
76 Assert.AreEqual(p.Join(), 100);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
77 }
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
78
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
79 [TestMethod]
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
80 public void JoinFailTest() {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
81 var p = new Promise<int>();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
82 p.Reject(new ApplicationException("failed"));
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
83
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
84 try {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
85 p.Join();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
86 throw new ApplicationException("WRONG!");
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
87 } catch (TargetInvocationException err) {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
88 Assert.AreEqual(err.InnerException.Message, "failed");
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
89 } catch {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
90 Assert.Fail("Got wrong excaption");
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
91 }
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
92 }
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
93
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
94 [TestMethod]
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
95 public void MapTest() {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
96 var p = new Promise<int>();
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
97
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
98 var p2 = p.Then(x => x.ToString());
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
99 p.Resolve(100);
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
100
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
101 Assert.AreEqual(p2.Join(), "100");
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
102 }
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
103
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
104 [TestMethod]
11
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
105 public void FixErrorTest() {
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
106 var p = new Promise<int>();
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
107
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
108 var p2 = p.Error(e => 101);
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
109
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
110 p.Reject(new Exception());
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
111
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
112 Assert.AreEqual(p2.Join(), 101);
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
113 }
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
114
6ec82bf68c8e refactoring
cin
parents: 10
diff changeset
115 [TestMethod]
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
116 public void ChainTest() {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
117 var p1 = new Promise<int>();
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
118
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
119 var p3 = p1.Chain(x => {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
120 var p2 = new Promise<string>();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
121 p2.Resolve(x.ToString());
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
122 return p2;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
123 });
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
124
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
125 p1.Resolve(100);
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
126
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
127 Assert.AreEqual(p3.Join(), "100");
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
128 }
0
279591fb4df3 initial commit
user@factory.site.local
parents:
diff changeset
129
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
130 [TestMethod]
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
131 public void PoolTest() {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
132 var pid = Thread.CurrentThread.ManagedThreadId;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
133 var p = AsyncPool.Invoke(() => Thread.CurrentThread.ManagedThreadId);
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
134
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
135 Assert.AreNotEqual(pid, p.Join());
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
136 }
10
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
137
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
138 [TestMethod]
13
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
139 public void WorkerPoolSizeTest() {
17
7cd4a843b4e4 Improved worker pool
cin
parents: 16
diff changeset
140 var pool = new WorkerPool(5, 10, 0);
13
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
141
20
1c3b3d518480 refactoring, sync
cin
parents: 19
diff changeset
142 Assert.AreEqual(5, pool.PoolSize);
13
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
143
22
5a35900264f5 implemented nonblocking wake singnals processing
cin
parents: 21
diff changeset
144 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
5a35900264f5 implemented nonblocking wake singnals processing
cin
parents: 21
diff changeset
145 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
5a35900264f5 implemented nonblocking wake singnals processing
cin
parents: 21
diff changeset
146 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
13
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
147
20
1c3b3d518480 refactoring, sync
cin
parents: 19
diff changeset
148 Assert.AreEqual(5, pool.PoolSize);
13
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
149
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
150 for (int i = 0; i < 100; i++)
22
5a35900264f5 implemented nonblocking wake singnals processing
cin
parents: 21
diff changeset
151 pool.Invoke(() => { Thread.Sleep(100000000); return 10; });
5a35900264f5 implemented nonblocking wake singnals processing
cin
parents: 21
diff changeset
152 Thread.Sleep(200);
20
1c3b3d518480 refactoring, sync
cin
parents: 19
diff changeset
153 Assert.AreEqual(10, pool.PoolSize);
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
154
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
155 pool.Dispose();
13
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
156 }
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
157
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
158 [TestMethod]
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
159 public void WorkerPoolCorrectTest() {
17
7cd4a843b4e4 Improved worker pool
cin
parents: 16
diff changeset
160 var pool = new WorkerPool(0,1000,100);
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
161
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
162 int iterations = 1000;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
163 int pending = iterations;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
164 var stop = new ManualResetEvent(false);
13
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
165
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
166 var count = 0;
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
167 for (int i = 0; i < iterations; i++) {
13
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
168 pool
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
169 .Invoke(() => 1)
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
170 .Then(x => Interlocked.Add(ref count, x))
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
171 .Then(x => Math.Log10(x))
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
172 .Anyway(() => {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
173 Interlocked.Decrement(ref pending);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
174 if (pending == 0)
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
175 stop.Set();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
176 });
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
177 }
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
178
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
179 stop.WaitOne();
13
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
180
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
181 Assert.AreEqual(iterations, count);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
182 Console.WriteLine("Max threads: {0}", pool.MaxRunningThreads);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
183 pool.Dispose();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
184
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
185 }
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
186
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
187 [TestMethod]
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
188 public void WorkerPoolDisposeTest() {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
189 var pool = new WorkerPool(5, 20);
20
1c3b3d518480 refactoring, sync
cin
parents: 19
diff changeset
190 Assert.AreEqual(5, pool.PoolSize);
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
191 pool.Dispose();
21
6a56df4ec59e DispatchPool works again, but performance is poor in some cases
cin
parents: 20
diff changeset
192 Thread.Sleep(500);
20
1c3b3d518480 refactoring, sync
cin
parents: 19
diff changeset
193 Assert.AreEqual(0, pool.PoolSize);
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
194 pool.Dispose();
13
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
195 }
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
196
b0feb5b9ad1c small fixes, WorkerPool still incomplete
cin
parents: 11
diff changeset
197 [TestMethod]
14
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
198 public void MTQueueTest() {
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
199 var queue = new MTQueue<int>();
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
200 int res;
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
201
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
202 queue.Enqueue(10);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
203 Assert.IsTrue(queue.TryDequeue(out res));
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
204 Assert.AreEqual(10, res);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
205 Assert.IsFalse(queue.TryDequeue(out res));
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
206
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
207 for (int i = 0; i < 1000; i++)
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
208 queue.Enqueue(i);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
209
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
210 for (int i = 0; i < 1000; i++) {
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
211 queue.TryDequeue(out res);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
212 Assert.AreEqual(i, res);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
213 }
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
214
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
215 int writers = 0;
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
216 int readers = 0;
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
217 var stop = new ManualResetEvent(false);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
218 int total = 0;
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
219
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
220 int itemsPerWriter = 10000;
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
221 int writersCount = 10;
14
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
222
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
223 for (int i = 0; i < writersCount; i++) {
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
224 Interlocked.Increment(ref writers);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
225 var wn = i;
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
226 AsyncPool
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
227 .InvokeNewThread(() => {
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
228 for (int ii = 0; ii < itemsPerWriter; ii++) {
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
229 queue.Enqueue(1);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
230 }
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
231 return 1;
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
232 })
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
233 .Anyway(() => Interlocked.Decrement(ref writers));
14
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
234 }
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
235
14
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
236 for (int i = 0; i < 10; i++) {
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
237 Interlocked.Increment(ref readers);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
238 var wn = i;
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
239 AsyncPool
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
240 .InvokeNewThread(() => {
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
241 int t;
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
242 do {
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
243 while (queue.TryDequeue(out t))
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
244 Interlocked.Add(ref total, t);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
245 } while (writers > 0);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
246 return 1;
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
247 })
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
248 .Anyway(() => {
14
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
249 Interlocked.Decrement(ref readers);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
250 if (readers == 0)
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
251 stop.Set();
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
252 });
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
253 }
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
254
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
255 stop.WaitOne();
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
256
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
257 Assert.AreEqual(itemsPerWriter * writersCount, total);
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
258 }
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
259
e943453e5039 Implemented interllocked queue
cin
parents: 13
diff changeset
260 [TestMethod]
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
261 public void ParallelMapTest() {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
262
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
263 int count = 100000;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
264
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
265 double[] args = new double[count];
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
266 var rand = new Random();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
267
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
268 for (int i = 0; i < count; i++)
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
269 args[i] = rand.NextDouble();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
270
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
271 var t = Environment.TickCount;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
272 var res = args.ParallelMap(x => Math.Sin(x*x), 4).Join();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
273
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
274 Console.WriteLine("Map complete in {0} ms", Environment.TickCount - t);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
275
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
276 t = Environment.TickCount;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
277 for (int i = 0; i < count; i++)
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
278 Assert.AreEqual(Math.Sin(args[i] * args[i]), res[i]);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
279 Console.WriteLine("Verified in {0} ms", Environment.TickCount - t);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
280 }
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
281
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
282 [TestMethod]
16
cin
parents: 15
diff changeset
283 public void ChainedMapTest() {
cin
parents: 15
diff changeset
284
34
dabf79fde388 fixed race condition in DispatchPool
cin
parents: 33
diff changeset
285 using (var pool = new WorkerPool(0,100,100)) {
16
cin
parents: 15
diff changeset
286 int count = 10000;
cin
parents: 15
diff changeset
287
cin
parents: 15
diff changeset
288 double[] args = new double[count];
cin
parents: 15
diff changeset
289 var rand = new Random();
cin
parents: 15
diff changeset
290
cin
parents: 15
diff changeset
291 for (int i = 0; i < count; i++)
cin
parents: 15
diff changeset
292 args[i] = rand.NextDouble();
cin
parents: 15
diff changeset
293
cin
parents: 15
diff changeset
294 var t = Environment.TickCount;
cin
parents: 15
diff changeset
295 var res = args
30
2fad2d1f4b03 small refactoring, cleanup.
cin
parents: 24
diff changeset
296 .ChainedMap(
16
cin
parents: 15
diff changeset
297 x => pool.Invoke(
cin
parents: 15
diff changeset
298 () => Math.Sin(x * x)
cin
parents: 15
diff changeset
299 ),
cin
parents: 15
diff changeset
300 4
cin
parents: 15
diff changeset
301 )
cin
parents: 15
diff changeset
302 .Join();
cin
parents: 15
diff changeset
303
cin
parents: 15
diff changeset
304 Console.WriteLine("Map complete in {0} ms", Environment.TickCount - t);
cin
parents: 15
diff changeset
305
cin
parents: 15
diff changeset
306 t = Environment.TickCount;
cin
parents: 15
diff changeset
307 for (int i = 0; i < count; i++)
cin
parents: 15
diff changeset
308 Assert.AreEqual(Math.Sin(args[i] * args[i]), res[i]);
cin
parents: 15
diff changeset
309 Console.WriteLine("Verified in {0} ms", Environment.TickCount - t);
cin
parents: 15
diff changeset
310 Console.WriteLine("Max workers: {0}", pool.MaxRunningThreads);
cin
parents: 15
diff changeset
311 }
cin
parents: 15
diff changeset
312 }
cin
parents: 15
diff changeset
313
cin
parents: 15
diff changeset
314 [TestMethod]
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
315 public void ParallelForEachTest() {
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
316
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
317 int count = 100000;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
318
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
319 int[] args = new int[count];
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
320 var rand = new Random();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
321
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
322 for (int i = 0; i < count; i++)
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
323 args[i] = (int)(rand.NextDouble() * 100);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
324
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
325 int result = 0;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
326
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
327 var t = Environment.TickCount;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
328 args.ParallelForEach(x => Interlocked.Add(ref result, x), 4).Join();
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
329
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
330 Console.WriteLine("Iteration complete in {0} ms, result: {1}", Environment.TickCount - t, result);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
331
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
332 int result2 = 0;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
333
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
334 t = Environment.TickCount;
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
335 for (int i = 0; i < count; i++)
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
336 result2 += args[i];
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
337 Assert.AreEqual(result2, result);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
338 Console.WriteLine("Verified in {0} ms", Environment.TickCount - t);
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
339 }
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
340
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
341 [TestMethod]
10
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
342 public void ComplexCase1Test() {
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
343 var flags = new bool[3];
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
344
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
345 // op1 (aync 200ms) => op2 (async 200ms) => op3 (sync map)
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
346
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
347 var p = PromiseHelper
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
348 .Sleep(200, "Alan")
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
349 .Cancelled(() => flags[0] = true)
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
350 .Chain(x =>
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
351 PromiseHelper
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
352 .Sleep(200, "Hi, " + x)
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
353 .Then(y => y)
10
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
354 .Cancelled(() => flags[1] = true)
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
355 )
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
356 .Cancelled(() => flags[2] = true);
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
357 Thread.Sleep(300);
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
358 p.Cancel();
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
359 try {
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
360 Assert.AreEqual(p.Join(), "Hi, Alan");
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
361 Assert.Fail("Shouldn't get here");
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
362 } catch (OperationCanceledException) {
10
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
363 }
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
364
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
365 Assert.IsFalse(flags[0]);
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
366 Assert.IsTrue(flags[1]);
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
367 Assert.IsTrue(flags[2]);
aa33d0bb8c0c implemeted new cancellable promises concept
cin
parents: 4
diff changeset
368 }
33
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
369
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
370 [TestMethod]
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
371 public void ChainedCancel1Test() {
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
372 // при отмене сцепленной асинхронной операции все обещание должно
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
373 // завершаться ошибкой OperationCanceledException
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
374 var p = PromiseHelper
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
375 .Sleep(1, "Hi, HAL!")
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
376 .Then(x => {
33
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
377 // запускаем две асинхронные операции
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
378 var result = PromiseHelper.Sleep(1000, "HEM ENABLED!!!");
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
379 // вторая операция отменяет первую до завершения
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
380 PromiseHelper
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
381 .Sleep(100, "HAL, STOP!")
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
382 .Then(() => result.Cancel());
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
383 return result;
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
384 });
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
385 try {
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
386 p.Join();
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
387 } catch (TargetInvocationException err) {
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
388 Assert.IsTrue(err.InnerException is OperationCanceledException);
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
389 }
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
390 }
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
391
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
392 [TestMethod]
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
393 public void ChainedCancel2Test() {
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
394 // при отмене цепочки обещаний, вложенные операции также должны отменяться
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
395 var pSurvive = new Promise<bool>();
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
396 var hemStarted = new ManualResetEvent(false);
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
397 var p = PromiseHelper
33
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
398 .Sleep(1, "Hi, HAL!")
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
399 .Chain(x => {
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
400 hemStarted.Set();
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
401 // запускаем две асинхронные операции
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
402 var result = PromiseHelper
76
c761fc982e1d Refactoring of the IPromise<T> interface
cin
parents: 73
diff changeset
403 .Sleep(10000, "HEM ENABLED!!!")
33
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
404 .Then(s => pSurvive.Resolve(false));
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
405
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
406 result
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
407 .Cancelled(() => pSurvive.Resolve(true));
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
408
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
409 return result;
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
410 });
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
411
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
412 hemStarted.WaitOne();
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
413 p.Cancel();
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
414
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
415 try {
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
416 p.Join();
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
417 } catch (OperationCanceledException) {
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
418 Assert.IsTrue(pSurvive.Join());
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
419 }
b255e4aeef17 removed the reference to the parent from the promise object this allows
cin
parents: 30
diff changeset
420 }
15
0f982f9b7d4d implemented parallel map and foreach for arrays
cin
parents: 14
diff changeset
421 }
4
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
422 }
381095ad0a69 Implab.Fx: implemented animation object
cin
parents: 0
diff changeset
423