diff options
author | Zoltan Varga <vargaz@gmail.com> | 2015-02-13 08:15:52 +0300 |
---|---|---|
committer | Zoltan Varga <vargaz@gmail.com> | 2015-02-13 08:15:52 +0300 |
commit | b45199d288776c537f98efd8fbdac4cb93347208 (patch) | |
tree | 5bab2ec684b33f479280c4e89a914ec4e11699ad /mcs/class/corlib | |
parent | 82554c4e89ec310a36ecf1b055fcfcd480228740 (diff) |
[corlib] Fix a race in LazyTest.EnsureSingleThreadSafeExecution ().
Diffstat (limited to 'mcs/class/corlib')
-rw-r--r-- | mcs/class/corlib/Test/System/LazyTest.cs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/mcs/class/corlib/Test/System/LazyTest.cs b/mcs/class/corlib/Test/System/LazyTest.cs index ce75180cb1b..0b3e042e309 100644 --- a/mcs/class/corlib/Test/System/LazyTest.cs +++ b/mcs/class/corlib/Test/System/LazyTest.cs @@ -114,6 +114,7 @@ namespace MonoTests.System public void EnsureSingleThreadSafeExecution () { counter = 42; + bool started = false; var l = new Lazy<int> (delegate () { return counter ++; }, true); bool failed = false; @@ -122,16 +123,20 @@ namespace MonoTests.System 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 (); |