3 using System
.Threading
;
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
);
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
52 pulseTest
.Message ("Main", "disposing");
55 pulseTest
.Message ("Main", "disposed");
59 private void ThreadMain ()
61 Monitor
.Enter (theLock
);
63 Monitor
.Pulse (theLock
);
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
);