From 2ed2fa1e48309bdb27b12be153f24018289e126c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Aug 2026 21:31:47 +0000 Subject: [PATCH 1/2] Initial plan From 45ef2331273562fcee5e075c3e9770ddbfab29f2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 4 Aug 2026 21:38:27 +0000 Subject: [PATCH 2/2] Mitigate thread exhaustion in GC THDChaos test Co-authored-by: VSadov <8218165+VSadov@users.noreply.github.com> --- src/tests/GC/Scenarios/THDChaos/livingobject.cs | 15 ++++++--------- src/tests/GC/Scenarios/THDChaos/thdchaos.cs | 8 ++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/tests/GC/Scenarios/THDChaos/livingobject.cs b/src/tests/GC/Scenarios/THDChaos/livingobject.cs index d88dd0c4fb0595..e01b0b06aa4bd4 100644 --- a/src/tests/GC/Scenarios/THDChaos/livingobject.cs +++ b/src/tests/GC/Scenarios/THDChaos/livingobject.cs @@ -24,7 +24,7 @@ public void ThreadStart( ) { // console synchronization Console.SetOut(TextWriter.Synchronized(Console.Out)); - if( iCounter%100 == 0) + if( Volatile.Read( ref iCounter )%100 == 0) { Console.Out.WriteLine( iCounter + " number of threads has been started" ); } @@ -43,9 +43,9 @@ public void ThreadStart( ) MethodContainer[ 0 ] = ( byte ) 1; MethodContainer[ MethodContainer.Length - 1 ] = ( byte ) 1; - IncreatCount( ); - - if( LivingObject.iCounter < ThdChaos.iThrd ) + // Atomically reserve a thread creation slot before starting a successor thread, + // so that no more than ThdChaos.iThrd successor threads are ever created. + if( IncreatCount( ) <= ThdChaos.iThrd ) { Thread Mv_Thread = new Thread( new ThreadStart (this.ThreadStart) ); Mv_Thread.Start( ); @@ -54,12 +54,9 @@ public void ThreadStart( ) } - public void IncreatCount() + public int IncreatCount() { - lock(this) - { - iCounter += 1; - } + return Interlocked.Increment( ref iCounter ); } } diff --git a/src/tests/GC/Scenarios/THDChaos/thdchaos.cs b/src/tests/GC/Scenarios/THDChaos/thdchaos.cs index 6906b63abc4c13..1f0d7f71f9020d 100644 --- a/src/tests/GC/Scenarios/THDChaos/thdchaos.cs +++ b/src/tests/GC/Scenarios/THDChaos/thdchaos.cs @@ -12,6 +12,7 @@ namespace DefaultNamespace { using System.Threading; using System; using System.IO; + using System.Runtime.InteropServices; public class ThdChaos { @@ -33,6 +34,13 @@ public static int Main( System.String [] Args ) iThrd = 20; } + // 32-bit Arm has a limited address space, creating too many threads at once + // can exhaust it and result in OutOfMemoryException. + if( RuntimeInformation.ProcessArchitecture == Architecture.Arm && iThrd > 5 ) + { + iThrd = 5; + } + ThdChaos Mv_ThdChaos = new ThdChaos(); MasterThread Mv_Thread = new MasterThread( iThrd ); return 100;