Last active
January 10, 2016 07:34
-
-
Save jkotas/6fb00a78442c72440963 to your computer and use it in GitHub Desktop.
Thread id scalability test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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