-
-
Save esdrubal/8ac96d62daf955ff07aa to your computer and use it in GitHub Desktop.
AutoResetEventTests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Threading; | |
using System; | |
using NUnit.Framework; | |
namespace MonoTests.System.Threading | |
{ | |
[TestFixture] | |
class AutoResetEventTests | |
{ | |
[Test] | |
public static void SetReset() | |
{ | |
var ev1 = new AutoResetEvent (false); | |
var ev2 = new AutoResetEvent (false); | |
var i = 0; | |
const int repeatCount = 20; | |
var threadStart = new ThreadStart (() => { | |
ev1.Set (); | |
ev1.Reset (); | |
ev2.Set (); | |
int waitResult = WaitHandle.WaitAny (new [] { ev1 }, | |
TimeSpan.FromSeconds (10)); | |
if (waitResult != WaitHandle.WaitTimeout) | |
Interlocked.Increment (ref i); | |
}); | |
for (var r = 0; r < repeatCount; r++) { | |
new Thread (threadStart).Start (); | |
ev2.WaitOne (2000, false); | |
} | |
#if NET_4_0 | |
Assert.AreEqual (repeatCount-1, i); | |
#else | |
Assert.AreEqual (0, i); | |
#endif | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment