4 // Tests for the 'synchronized' method attribute
8 using System.Threading;
9 using System.Runtime.CompilerServices;
13 // We use Monitor.Pulse to test that the object is synchronized
15 [MethodImplAttribute(MethodImplOptions.Synchronized)]
18 //Monitor.Enter (this);
22 [MethodImplAttribute(MethodImplOptions.Synchronized)]
23 public static int test_static () {
24 Monitor.Pulse (typeof (Tests));
28 [MethodImplAttribute(MethodImplOptions.Synchronized)]
29 public int test_exception () {
31 throw new Exception ("A");
34 [MethodImplAttribute(MethodImplOptions.Synchronized)]
35 public virtual int test_virtual () {
40 public static bool is_synchronized (object o) {
44 catch (SynchronizationLockException ex) {
50 public delegate int Delegate1 ();
52 static public int Main (String[] args) {
53 Tests b = new Tests ();
56 Console.WriteLine ("Test1...");
58 if (is_synchronized (b))
61 Console.WriteLine ("Test2...");
63 if (is_synchronized (typeof (Tests)))
66 Console.WriteLine ("Test3...");
70 catch (SynchronizationLockException ex) {
73 catch (Exception ex) {
76 if (is_synchronized (b))
79 Console.WriteLine ("Test4...");
81 if (is_synchronized (b))
84 Console.WriteLine ("Test5...");
85 Delegate1 d = new Delegate1 (b.test);
87 if (is_synchronized (b))
90 Console.WriteLine ("Test6...");
91 d = new Delegate1 (test_static);
93 if (is_synchronized (typeof (Tests)))
96 Console.WriteLine ("Test7...");
97 d = new Delegate1 (b.test_virtual);
99 if (is_synchronized (b))
102 Console.WriteLine ("Test8...");
103 d = new Delegate1 (b.test_exception);
107 catch (SynchronizationLockException ex) {
110 catch (Exception ex) {
113 if (is_synchronized (b))