If I spawn various Threads, and tell them all to use the same method:
internal class Program {
private static DoSomething() {
int result = 0;
Thread.Sleep(1000);
result++;
int ID = Thread.CurrentThread.ManagedThreadId;
Console.WriteLine("Thread {0} return {1}", ID, result);
}
private static Main() {
Thread[] threads = new Thread[50];
for (int i = 0; i < 50; i++)
threads[i] = new Thread(DoSomething);
foreach (Thread t in threads)
t.Start();
}
}
Will all the Threads share the same stack? When I run the program all Threads return 1, so I guess the answer is no, but then does that mean that the CLR makes different copies of the method in memory?