2010-04-19 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / tests / shared-generic-synchronized.2.cs
blobb7ff6475d23cdb14ba9877754c6a53446d341625
1 //
2 // shared-generic-synchronized.2.cs:
3 //
4 // Tests for the 'synchronized' method attribute in shared generic methods
5 //
7 using System;
8 using System.Threading;
9 using System.Runtime.CompilerServices;
11 public class Test<T> {
13 [MethodImplAttribute(MethodImplOptions.Synchronized)]
14 public int test () {
15 Monitor.Exit (this);
16 Monitor.Enter (this);
17 return 2 + 2;
20 [MethodImplAttribute(MethodImplOptions.Synchronized)]
21 public static int test_static () {
22 Monitor.Exit (typeof (Test<T>));
23 Monitor.Enter (typeof (Test<T>));
24 return 2 + 2;
27 [MethodImplAttribute(MethodImplOptions.Synchronized)]
28 public int test_exception () {
29 Monitor.Exit (this);
30 throw new Exception ("A");
33 [MethodImplAttribute(MethodImplOptions.Synchronized)]
34 public virtual int test_virtual () {
35 Monitor.Exit (this);
36 Monitor.Enter (this);
37 return 2 + 2;
41 class main {
42 public delegate int Delegate1 ();
44 static public int Main (String[] args) {
45 Test<string> b = new Test<string> ();
46 int res;
48 Console.WriteLine ("Test1...");
49 b.test ();
50 Console.WriteLine ("Test2...");
51 Test<string>.test_static ();
52 Console.WriteLine ("Test3...");
53 try {
54 b.test_exception ();
56 catch (SynchronizationLockException ex) {
57 return 1;
59 catch (Exception ex) {
60 // OK
63 Console.WriteLine ("Test4...");
64 b.test_virtual ();
66 Console.WriteLine ("Test5...");
67 Delegate1 d = new Delegate1 (b.test);
68 res = d ();
70 Console.WriteLine ("Test6...");
71 d = new Delegate1 (Test<string>.test_static);
72 res = d ();
74 Console.WriteLine ("Test7...");
75 d = new Delegate1 (b.test_virtual);
76 res = d ();
78 Console.WriteLine ("Test8...");
79 d = new Delegate1 (b.test_exception);
80 try {
81 d ();
83 catch (SynchronizationLockException ex) {
84 return 2;
86 catch (Exception ex) {
87 // OK
90 return 0;