(I'm interested in the .NET CLR)
What exactly happens when one thread changes the object a variable references while another thread is executing a method on the original object?
For example, say the type Foo
has a variable 'Bar' of the type Bar
, and Bar
has no class-level state (for now at least, I'd like to keep this scenario simple):
// Thread 1
foo.Bar = new Bar();
foo.Bar.SomeMethod();
In the meantime, before this finishes executing ...
// Thread 2
foo.Bar = new Bar();
What happens to the method that is (was?) executing on Thread 1? Is everything it needs to complete already on the stack?
Does it change things if thread 2 does this instead?
foo.Bar = null;