Think about some kind of read-modify-write operation. For example, imagine we want to clear a bit. Now imagine another core is setting a bit in the same memory location at the same time. Without a LOCK prefix, the following could happen:
- Core A reads the memory location.
- Core B reads the same memory location.
- Core A sets a bit.
- Core B clears a different bit.
- Core A writes the result to the memory location.
- Core B writes the result to the same memory location.
Oops, the bit set done by core A was lost.
The LOCK prefix ensures that core B's read of the memory location cannot take place between core A's read and core A's write.
In the bad old days, the LOCK prefix pretty much locked the entire bus. This would ensure that the memory location wasn't read, but it would also ensure every other memory location wasn't read either! On modern CPUs, it just locks the cache line, allowing other cores to do all kinds of other operations, just not access that memory location (or any memory location that shares a cache line with it).