The MSDN documentation for Interlocked.Increment
states:
This method handles an overflow condition by wrapping: if location = Int32.MaxValue, location + 1 = Int32.MinValue. No exception is thrown.
What does “location + 1” mean in this context? If Increment
alters the memory location next to the location field, isn't this likely to lead to corruption in the .NET runtime, given that this adjacent location could be anything (object references, class metadata, etc)?
location
is simply the name of an int variable. So sayinglocation + 1
is just a normal mathematical statement. – Anthealocation = Int32.MaxValue
so location + 1 would overflow toInt32.MinValue
– Tailrace=
to represent equality rather than assignment. I figured that I was probably missing something obvious. – Spheroid