public void EnsureSingleThreadSafeExecution ()
{
counter = 42;
+ bool started = false;
var l = new Lazy<int> (delegate () { return counter ++; }, true);
bool failed = false;
for (int i = 0; i < threads.Length; ++i) {
threads [i] = new Thread (delegate () {
lock (monitor) {
- if (!Monitor.Wait (monitor, 2000))
- failed = true;
+ if (!started) {
+ if (!Monitor.Wait (monitor, 2000))
+ failed = true;
+ }
}
int val = l.Value;
});
}
for (int i = 0; i < threads.Length; ++i)
threads [i].Start ();
- lock (monitor)
+ lock (monitor) {
+ started = true;
Monitor.PulseAll (monitor);
+ }
for (int i = 0; i < threads.Length; ++i)
threads [i].Join ();