/
shared-generic-synchronized.2.cs
92 lines (77 loc) · 1.78 KB
/
shared-generic-synchronized.2.cs
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
//
// shared-generic-synchronized.2.cs:
//
// Tests for the 'synchronized' method attribute in shared generic methods
//
using System;
using System.Threading;
using System.Runtime.CompilerServices;
public class Test<T> {
[MethodImplAttribute(MethodImplOptions.Synchronized)]
public int test () {
Monitor.Exit (this);
Monitor.Enter (this);
return 2 + 2;
}
[MethodImplAttribute(MethodImplOptions.Synchronized)]
public static int test_static () {
Monitor.Exit (typeof (Test<T>));
Monitor.Enter (typeof (Test<T>));
return 2 + 2;
}
[MethodImplAttribute(MethodImplOptions.Synchronized)]
public int test_exception () {
Monitor.Exit (this);
throw new Exception ("A");
}
[MethodImplAttribute(MethodImplOptions.Synchronized)]
public virtual int test_virtual () {
Monitor.Exit (this);
Monitor.Enter (this);
return 2 + 2;
}
}
class main {
public delegate int Delegate1 ();
static public int Main (String[] args) {
Test<string> b = new Test<string> ();
int res;
Console.WriteLine ("Test1...");
b.test ();
Console.WriteLine ("Test2...");
Test<string>.test_static ();
Console.WriteLine ("Test3...");
try {
b.test_exception ();
}
catch (SynchronizationLockException ex) {
return 1;
}
catch (Exception ex) {
// OK
}
Console.WriteLine ("Test4...");
b.test_virtual ();
Console.WriteLine ("Test5...");
Delegate1 d = new Delegate1 (b.test);
res = d ();
Console.WriteLine ("Test6...");
d = new Delegate1 (Test<string>.test_static);
res = d ();
Console.WriteLine ("Test7...");
d = new Delegate1 (b.test_virtual);
res = d ();
Console.WriteLine ("Test8...");
d = new Delegate1 (b.test_exception);
try {
d ();
}
catch (SynchronizationLockException ex) {
return 2;
}
catch (Exception ex) {
// OK
}
return 0;
}
}