In the .NET memory model, reading and writing your own integer types less than or equal to the size of your platform pointer (i.e. int for 32-bit, long for 64-bit) is atomic. Atomic means that you can read and write without using locks, and you will never read or write incomplete (that is, halfway between the write value).
However, .NET does not guarantee that records will be immediately visible to other streams (which means that you can write to stream A, then read on stream B and read the old value). On x86, you get immediate visibility with the architecture, but on other platforms you need to use the volatile or Thread.MemoryBarrier after recording. lock puts a memory barrier in place for you, so you donβt have to worry about it.
Another thing to think about is how you use this class. Although one access is atomic, a lock will still be needed if you want to read or write multiple fields as a single atomic operation. (well, not technically always - there are certain optimizations that you can sometimes do, but stick to simple things while you study)
So, in short: lock is pretty much overkill - you can get rid of it and use volatile / barriers if you need immediate visibility.
source share