Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit f3796c7

Browse files
authored
Fix waitone test (#15728)
Fixes https://github.com/dotnet/coreclr/issues/15098: - Probably a timing issue, changed to use Thread.Join() instead of sleeps
1 parent e79a4d5 commit f3796c7

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

tests/src/baseservices/threading/mutex/misc/waitone2.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -422,18 +422,17 @@ public bool NegTest1()
422422
public bool NegTest2()
423423
{
424424
bool retVal = true;
425-
Thread thread = null;
426425

427426
TestLibrary.TestFramework.BeginScenario("NegTest2: ObjectDisposedException should be thrown if current instance has already been disposed");
428427

429428
try
430429
{
431430
m_Mutex = new Mutex();
432431

433-
thread = new Thread(new ThreadStart(DisposeMutex));
432+
var thread = new Thread(new ThreadStart(DisposeMutex));
433+
thread.IsBackground = true;
434434
thread.Start();
435-
Thread.Sleep(c_DEFAULT_SLEEP_TIME / 5); // To avoid race
436-
Thread.Sleep(c_DEFAULT_SLEEP_TIME);
435+
thread.Join();
437436
m_Mutex.WaitOne(Timeout.Infinite);
438437

439438
TestLibrary.TestFramework.LogError("103", "ObjectDisposedException is not thrown if current instance has already been disposed");
@@ -450,11 +449,6 @@ public bool NegTest2()
450449
}
451450
finally
452451
{
453-
if (null != thread)
454-
{
455-
thread.Join();
456-
}
457-
458452
if (null != m_Mutex)
459453
{
460454
((IDisposable)m_Mutex).Dispose();
@@ -558,7 +552,6 @@ private void NeverReleaseMutex()
558552

559553
private void DisposeMutex()
560554
{
561-
Thread.Sleep(c_DEFAULT_SLEEP_TIME);
562555
((IDisposable)m_Mutex).Dispose();
563556
}
564557

0 commit comments

Comments
 (0)