Thread Local Storage and local method variables
- by miguel
In c#, each thread has its own stack space.
If this is the case, why is the following code not thread-safe? (It is stated that this code is thread-safe on this post: Locking in C#
class Foo
{
private int count = 0;
public void TrySomething()
{
count++;
}
}
As count is an int (stack variable), surely this value would be isolated to an individual thread, on its own stack, and therefore thread-safe?
I am probably missing something here, but I dont understand what is actually in Thread Local Storage if not stack-based variables for the thread?