Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/tests/GC/Scenarios/THDChaos/livingobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}
Expand All @@ -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( );
Expand All @@ -54,12 +54,9 @@ public void ThreadStart( )
}


public void IncreatCount()
public int IncreatCount()
{
lock(this)
{
iCounter += 1;
}
return Interlocked.Increment( ref iCounter );
}

}
Expand Down
8 changes: 8 additions & 0 deletions src/tests/GC/Scenarios/THDChaos/thdchaos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace DefaultNamespace {
using System.Threading;
using System;
using System.IO;
using System.Runtime.InteropServices;
using TestLibrary;

public class ThdChaos
Expand Down Expand Up @@ -40,6 +41,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;
Expand Down