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) {
52 [MethodImpl(MethodImplOptions.Synchronized)]
53 public static void Run ()
58 public delegate int Delegate1 ();
60 static public int Main (String[] args) {
61 Tests b = new Tests ();
64 Console.WriteLine ("Test1...");
66 if (is_synchronized (b))
69 Console.WriteLine ("Test2...");
71 if (is_synchronized (typeof (Tests)))
74 Console.WriteLine ("Test3...");
78 catch (SynchronizationLockException ex) {
81 catch (Exception ex) {
84 if (is_synchronized (b))
87 Console.WriteLine ("Test4...");
89 if (is_synchronized (b))
92 Console.WriteLine ("Test5...");
93 Delegate1 d = new Delegate1 (b.test);
95 if (is_synchronized (b))
98 Console.WriteLine ("Test6...");
99 d = new Delegate1 (test_static);
101 if (is_synchronized (typeof (Tests)))
104 Console.WriteLine ("Test7...");
105 d = new Delegate1 (b.test_virtual);
107 if (is_synchronized (b))
110 Console.WriteLine ("Test8...");
111 d = new Delegate1 (b.test_exception);
115 catch (SynchronizationLockException ex) {
118 catch (Exception ex) {
121 if (is_synchronized (b))
124 Monitor.Enter (typeof (Gen<>));
125 Thread t = new Thread (() =>
131 Monitor.Exit (typeof (Gen<>));