Skip to content

Instantly share code, notes, and snippets.

@jkotas
Last active January 10, 2016 07:34
Show Gist options
  • Save jkotas/6fb00a78442c72440963 to your computer and use it in GitHub Desktop.
Save jkotas/6fb00a78442c72440963 to your computer and use it in GitHub Desktop.
Thread id scalability test
using System;
using System.Runtime.CompilerServices;
using System.Threading;
class Program
{
static void Work()
{
ManagedThreadId.Current.ToString();
}
class ObjectWithSlowFinalizer
{
~ObjectWithSlowFinalizer()
{
Thread.Sleep(5000);
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
static void CreateObjectWithLongFinalizer()
{
new ObjectWithSlowFinalizer().ToString();
}
static void Main(string[] args)
{
for (int i = 0; i < 10000; i++)
new Thread(Work).Start();
CreateObjectWithLongFinalizer();
for (int i = 0; i < 10000; i++)
new Thread(Work).Start();
Thread.Sleep(10000);
GC.Collect();
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment