[runtime] Accomplish BITCODE build symbol sharing with only make (#3329)
[mono-project.git] / mono / tests / monitor-resurrection.cs
blob205d10ca16e98838c73ff9da01053e166f4ce530
1 using System;
2 using System.Collections;
3 using System.Threading;
4 using System.Collections.Generic;
6 public class Foo {
7 static Foo resurrect;
8 static Foo reference;
9 static List<Foo> list = new List<Foo> ();
11 ~Foo() {
12 resurrect = this;
15 public static void EnterMonitor (object obj)
17 for (int i = 0; i < 257; i++)
18 Monitor.Enter (obj);
21 public static void ExitMonitor (object obj)
23 for (int i = 0; i < 257; i++)
24 Monitor.Exit (obj);
27 public static void CreateFoo (int level)
29 if (level == 0) {
30 reference = new Foo ();
32 /* Allocate a MonoThreadsSync for the object */
33 EnterMonitor (reference);
34 ExitMonitor (reference);
35 reference = null;
36 } else {
37 CreateFoo (level - 1);
41 public static int Main() {
42 /* Allocate an object down the stack so it doesn't get pinned */
43 CreateFoo (100);
45 Console.WriteLine (".");
47 /* resurrect obj */
48 GC.Collect ();
49 GC.WaitForPendingFinalizers ();
51 /* Allocate MonoThreadsSyncs for another thread that are locked */
52 Thread t = new Thread (new ThreadStart (resurrect.Func));
53 t.Start ();
54 t.Join ();
56 /* Make sure that none of the other structures overlap with the original one */
57 Monitor.Enter (resurrect);
58 return 0;
61 public void Func () {
62 for (int i = 0; i < 100; i++) {
63 Foo foo = new Foo ();
64 /* Make sure these are not collected */
65 list.Add (foo);
67 EnterMonitor (foo);