We already know that each thread has its own call stack; hence, stack-allocated data is state-specific to a particular thread (for example, local variables and parameters that are being passed to methods). In the “Synchronization Primitives” section we discuss how to share state between threads, preferably in a safe manner. For now, let’s focus on other forms of thread-specific state.
Static state is isolated on a per-application domain basis. Because multiple threads can be executing in the same application domain, such static state is shared across those threads. This behavior can be changed by applying the
ThreadStatic attribute to a static field. First, let’s show multiple threads accessing ...