Please forgive me if the question is asked before, as I cannot find a good keyword to search for it. So if you have any recommendation for the keyword for the problem below, please let me know.
So the question is: suppose I have a class
class Test
{
public int testProp;
}
When I do something like
var testInstance = new Test();
testInstance.testProp += 10;
will the address of the testProp
still be the same as it is before the + operation? When I tried with the Visual Studio disassembly window, I see that it seems to copy the new value to the same address (Please correct me here as I'm in no where familiar with Assembly lang).
I'm asking because in case of multiple thread access the property and increase its value concurrently
var list = new List<Task>();
for (var z = 0; z < 2000; z++)
{
list.Add(Task.Run(() =>
{
testInstance.testProp+=10;
}));
}
sometimes it would give me 20000, but sometimes only 19990 or less, so I'm quite confused if the address of testProp
is changed, and if not how is the value of the address is read that makes the sum less than 20000 in this case?