Skip to content

Instantly share code, notes, and snippets.

@esdrubal
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esdrubal/8ac96d62daf955ff07aa to your computer and use it in GitHub Desktop.
Save esdrubal/8ac96d62daf955ff07aa to your computer and use it in GitHub Desktop.
AutoResetEventTests
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