[System] Tweak socket test
[mono-project.git] / mono / tests / sgen-bridge-xref.cs
blob82892803ce9a30d30e1f2cabb45b6de39025be10
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Threading;
6 public class Bridge {
7 public int __test;
8 public string id;
9 public List<object> link = new List<object> ();
11 ~Bridge () {
15 class Driver {
16 static WeakReference<Bridge> root, child;
18 static void SetupLinks () {
19 var a = new Bridge () { id = "bridge" };
20 var b = new Bridge () { id = "child" };
21 a.link.Add (b);
22 a.__test = 1;
23 b.__test = 0;
24 root = new WeakReference<Bridge> (a, true);
25 child = new WeakReference<Bridge> (b, true);
28 static int Main ()
30 var t = new Thread (SetupLinks);
31 t.Start ();
32 t.Join ();
34 GC.Collect ();
35 Bridge a, b;
36 a = b = null;
37 Console.WriteLine ("try get A {0}", root.TryGetTarget (out a));
38 Console.WriteLine ("try get B {0}", child.TryGetTarget (out b));
39 Console.WriteLine ("a is null {0}", a == null);
40 Console.WriteLine ("b is null {0}", b == null);
41 if (a == null || b == null)
42 return 1;
44 Console.WriteLine ("a test {0}", a.__test);
45 Console.WriteLine ("b test {0}", b.__test);
47 if (a.__test != 1 || b.__test != 3)
48 return 2;
50 return 0;