diff --git a/src/coreclr/tests/issues.targets b/src/coreclr/tests/issues.targets index 96c3d5241c751a9a872a29067f6defe76d580aa7..0e518744df04eb114fdadc244d6dedd7a79c3c02 100644 --- a/src/coreclr/tests/issues.targets +++ b/src/coreclr/tests/issues.targets @@ -571,24 +571,6 @@ 17129 - - 22303 - - - 22303 - - - 22303 - - - 22303 - - - 22303 - - - 22303 - diff --git a/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass.csproj b/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass.csproj index a3db344e61127af61f4dca650b269a1f89fa84e1..3b30552d0cf0526f60baad30f1ddd0e2dbea0d29 100644 --- a/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass.csproj +++ b/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTClass.csproj @@ -10,7 +10,7 @@ {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} ..\..\ true - null + "" 1 true diff --git a/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTString.csproj b/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTString.csproj index 2e34b48f8b6cc3445ec5f69d999f21c94bbcd0d0..b0cb6f0e20e2a7c9546d6fa41ce12b52201dc0bc 100644 --- a/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTString.csproj +++ b/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/CompareExchangeTString.csproj @@ -12,7 +12,7 @@ true BuildAndRun 1 - empty + "hello" diff --git a/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetclass.cs b/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetclass.cs index a119d6b8da7f9a4bec3e932945308db80ef15565..956efba686659d1ddab58302a58300bbf13b035d 100644 --- a/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetclass.cs +++ b/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetclass.cs @@ -6,7 +6,7 @@ class Class1 { - + static int Main(string[] args) { int rValue = 0; @@ -21,21 +21,21 @@ static int Main(string[] args) threads[i] = new Thread(new ParameterizedThreadStart(tsi.ThreadWorker)); threads[i].Start(kcIn); } - + tsi.Signal(); Console.WriteLine("Joining threads"); - for(int i=0;i( + } + while ((object)initialValue != Interlocked.CompareExchange( ref Val, newValue, initialValue)); + return newValue; } @@ -104,7 +106,7 @@ public string ClassVal return retVal; } } - + public static KrisClass operator +(KrisClass kc1, KrisClass kc2) { return new KrisClass(kc1.ClassVal + kc2.ClassVal); @@ -112,7 +114,7 @@ public string ClassVal public static bool operator ==(KrisClass kc1, KrisClass kc2) { - if(kc1.ClassVal == kc2.ClassVal) + if (kc1.ClassVal == kc2.ClassVal) return true; else return false; @@ -120,26 +122,26 @@ public string ClassVal public static bool operator !=(KrisClass kc1, KrisClass kc2) { - if(kc1.ClassVal != kc2.ClassVal) + if (kc1.ClassVal != kc2.ClassVal) return true; else return false; } - public override bool Equals(object o) - { - try - { - return (bool) (this == (KrisClass) o); - } - catch - { - return false; - } - } - - public override int GetHashCode() - { - return 0; - } + public override bool Equals(object o) + { + try + { + return (bool)(this == (KrisClass)o); + } + catch + { + return false; + } + } + + public override int GetHashCode() + { + return 0; + } } \ No newline at end of file diff --git a/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetstring.cs b/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetstring.cs index 82f1520fb20a43de6333fa7b58a2d569a5e3397c..386b081157acecb299b6b1a9540cc0a2c8dd4fc5 100644 --- a/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetstring.cs +++ b/src/coreclr/tests/src/baseservices/threading/interlocked/compareexchange/compareexchangetstring.cs @@ -95,8 +95,9 @@ private string AddToTotal(string addend) initialValue = Val; newValue = initialValue + addend; } - while (initialValue != Interlocked.CompareExchange( + while ((object)initialValue != Interlocked.CompareExchange( ref Val, newValue, initialValue)); + return newValue; } } diff --git a/src/coreclr/tests/src/baseservices/threading/interlocked/exchange/exchangetstring.cs b/src/coreclr/tests/src/baseservices/threading/interlocked/exchange/exchangetstring.cs index 6c6f4865e8ee94105c5b54f58952b8dd7b908340..26cfe38bf986db56637b6ad5fff2b11829f455e0 100644 --- a/src/coreclr/tests/src/baseservices/threading/interlocked/exchange/exchangetstring.cs +++ b/src/coreclr/tests/src/baseservices/threading/interlocked/exchange/exchangetstring.cs @@ -6,7 +6,7 @@ using System.Collections; class Class1 -{ +{ static int Main(string[] args) { int rValue = 0; @@ -17,10 +17,10 @@ static int Main(string[] args) for (int i = 0; i < threads.Length - 1; i++) { if (i % 2 == 0) - threads[i] = new Thread(new + threads[i] = new Thread(new ParameterizedThreadStart(tsi.ThreadWorkerA)); else - threads[i] = new Thread(new + threads[i] = new Thread(new ParameterizedThreadStart(tsi.ThreadWorkerB)); threads[i].Start(args); @@ -30,12 +30,6 @@ static int Main(string[] args) threads[threads.Length - 1] = new Thread(new ThreadStart(tsi.ThreadChecker)); threads[threads.Length - 1].Start(); - //Added to prevent races where Checker does not get to Wait before ManualEvent is Set - while(tsi.ThreadCount < 100) - { - Thread.Sleep(100); - } - Thread.Sleep(100); tsi.Signal(); Console.WriteLine("Joining threads"); @@ -57,11 +51,8 @@ public class ThreadSafe private string newValueA = "hello"; private string newValueB = "world"; private bool success; - public volatile int ThreadCount = 0; - private volatile static object syncroot = new object(); - - public ThreadSafe(): this(10000) { } + public ThreadSafe() : this(10000) { } public ThreadSafe(int loops) { @@ -81,28 +72,23 @@ public void ThreadWorkerA(object obj) string ret = null; // get the value - if(0 < str.Length) + if (0 < str.Length) { - if("null" == str[0]) + if ("null" == str[0]) newValueA = null; - else if("empty" == str[0]) + else if ("empty" == str[0]) newValueA = string.Empty; else newValueA = str[0]; } - - lock(syncroot) - { - ThreadCount++; - } - + signal.WaitOne(); for (int i = 0; i < numberOfIterations; i++) { ret = Interlocked.Exchange(ref curVal, newValueA); - + // Check return value - if(ret != newValueB && ret != newValueA && ret != "start string") + if (ret != newValueB && ret != newValueA && ret != "start string") { Console.WriteLine(ret + "," + newValueB + "," + newValueA); success = false; @@ -117,28 +103,24 @@ public void ThreadWorkerB(object obj) string ret = null; // get the value - if(2 == str.Length) + if (2 == str.Length) { - if("null" == str[1]) + if ("null" == str[1]) newValueB = null; - else if("empty" == str[1]) + else if ("empty" == str[1]) newValueB = string.Empty; else newValueB = str[1]; } - lock(syncroot) - { - ThreadCount++; - } + signal.WaitOne(); - signal.WaitOne(); for (int i = 0; i < numberOfIterations; i++) { ret = Interlocked.Exchange(ref curVal, newValueB); // Check return value - if(ret != newValueB && ret != newValueA && ret != "start string") + if (ret != newValueB && ret != newValueA && ret != "start string") { Console.WriteLine(ret + "," + newValueB + "," + newValueA); success = false; @@ -148,17 +130,18 @@ public void ThreadWorkerB(object obj) public void ThreadChecker() { - lock(syncroot) - { - ThreadCount++; - } - signal.WaitOne(); + + while(curVal == "start string") + { + Thread.Sleep(0); + } + string tmpVal; for (int i = 0; i < numberOfIterations; i++) { tmpVal = curVal; - if (tmpVal != newValueB && tmpVal != newValueA && tmpVal != "start string") + if (tmpVal != newValueB && tmpVal != newValueA) { Console.WriteLine(tmpVal + "," + newValueB + "," + newValueA); success = false;