[rx] add missing project file generator helper files.
[mono-project.git] / mono / tests / bug-561239.cs
blobf82c44af57fa3d795864e48f005e5fe500d42ff9
1 using System;
2 using System.IO;
3 using System.Threading;
5 public class PulseTest
7 private bool startedUp = false;
8 private int threadNum = 0;
9 private object theLock = new object ();
11 public static void Main (string[] args)
13 int lastThreadNum = 0;
15 for (int i = 0; i < 100; ++i) {
17 * Start a thread going.
19 PulseTest pulseTest = new PulseTest ();
20 pulseTest.threadNum = ++ lastThreadNum;
21 Thread sysThread = new Thread (pulseTest.ThreadMain);
24 * Block thread from doing anything.
26 Monitor.Enter (pulseTest.theLock);
29 * Now start it.
31 sysThread.Start ();
34 * Wait for pulsetest thread to call Monitor.Wait().
36 while (!pulseTest.startedUp) {
37 pulseTest.Message ("Main", "waiting");
38 Monitor.Wait (pulseTest.theLock);
39 pulseTest.Message ("Main", "woken");
41 Monitor.Exit (pulseTest.theLock);
44 * Whilst it is sitting in Monitor.Wait, kill it off.
46 * Without the patch, the wait event sits in mon->wait_list,
47 * even as the mon struct gets recycled onto monitor_freelist.
49 * With the patch, the event is unlinked when the mon struct
50 * gets recycled.
52 pulseTest.Message ("Main", "disposing");
53 sysThread.Abort ();
54 sysThread.Join ();
55 pulseTest.Message ("Main", "disposed");
59 private void ThreadMain ()
61 Monitor.Enter (theLock);
62 startedUp = true;
63 Monitor.Pulse (theLock);
64 while (true) {
65 Message ("ThreadMain", "waiting");
68 * This puts an event onto mon->wait_list.
69 * Then Main() does a sysThread.Abort() and
70 * the event is left on mon->wait_list.
72 Monitor.Wait (theLock);
73 Message ("ThreadMain", "woken");
77 private void Message (string func, string msg)
79 Console.WriteLine ("{0}[{1}]*: {2}", func, threadNum, msg);