blob: a6c3ac9175a975360b6ef661624d3c2f9d7a6f2e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
using System;
using System.Threading;
using System.Threading.Tasks;
class Program
{
public static int Main ()
{
var mre = new ManualResetEvent (false);
var mre_l = new ManualResetEvent (false);
Action a = async () => {
await Task.Factory.StartNew (() => {
if (!mre_l.WaitOne (3000))
throw new ApplicationException ("1");
}).ConfigureAwait (false);
if (mre_l.WaitOne ())
mre.Set ();
};
a ();
mre_l.Set ();
if (!mre.WaitOne (3000))
return 1;
mre.Reset ();
mre_l.Reset ();
Action a2 = async delegate {
await Task.Factory.StartNew (() => {
if (!mre_l.WaitOne (3000))
throw new ApplicationException ("2");
}).ConfigureAwait (false);
if (mre_l.WaitOne ())
mre.Set ();
};
a2 ();
mre_l.Set ();
if (!mre.WaitOne (3000))
return 2;
mre_l.Reset ();
Func<string, Task<string>> f = async l => {
var t = await Task.Factory.StartNew (() => {
if (!mre_l.WaitOne (3000))
throw new ApplicationException ("3");
return l;
}).ConfigureAwait (false);
return t;
};
var r = f ("a");
mre_l.Set ();
if (!r.Wait (3000))
return 3;
if (r.Result != "a")
return 31;
mre_l.Reset ();
Func<decimal, Task<decimal>> f2 = async delegate (decimal l) {
var t = await Task.Factory.StartNew (() => {
if (!mre_l.WaitOne (3000))
throw new ApplicationException ("4");
return l;
}).ConfigureAwait (false);
return t;
};
var r2 = f2 (decimal.MaxValue);
mre_l.Set ();
if (!r2.Wait (3000))
return 4;
if (r2.Result != decimal.MaxValue)
return 41;
f2 = async delegate (decimal l) {
return l;
};
r2 = f2 (88);
if (r2.Result != 88)
return 5;
return 0;
}
}
|