[System] UriKind.RelativeOrAbsolute workaround.
[mono.git] / mono / tests / monitor-resurrection.cs
1 using System; 
2 using System.Collections; 
3 using System.Threading;
4 using System.Collections.Generic;
5
6 public class Foo  {
7         static Foo resurrect;
8         static Foo reference;
9         static List<Foo> list = new List<Foo> ();
10
11         ~Foo() {
12                 resurrect = this;
13         }
14
15         public static void CreateFoo (int level)
16         {
17                 if (level == 0) {
18                         reference = new Foo ();
19
20                         /* Allocate a MonoThreadsSync for the object */
21                         Monitor.Enter (reference);
22                         Monitor.Exit (reference);
23                         reference = null;
24                 } else {
25                         CreateFoo (level - 1);
26                 }
27         }
28
29         public static int Main() {
30                 /* Allocate an object down the stack so it doesn't get pinned */
31                 CreateFoo (100);
32
33                 Console.WriteLine (".");
34
35                 /* resurrect obj */
36                 GC.Collect ();
37                 GC.WaitForPendingFinalizers ();
38
39                 /* Allocate MonoThreadsSyncs for another thread that are locked */
40                 Thread t = new Thread (new ThreadStart (resurrect.Func));
41                 t.Start ();
42                 t.Join ();
43
44                 /* Make sure that none of the other structures overlap with the original one */
45                 Monitor.Enter (resurrect);
46                 return 0;
47         }
48
49         public void Func () {
50                 for (int i = 0; i < 100; i++) {
51                         Foo foo = new Foo ();
52                         /* Make sure these are not collected */
53                         list.Add (foo);
54
55                         Monitor.Enter (foo);
56                 }
57         }
58
59