While I was looking at the Intel manuals, I've come across this statement:
Quote
This instruction can be used with a LOCK prefix to allow the instruction to be
executed atomically.
What does the word atomically mean in this instance?
Thanks,
Rags
Well, rags, actually LOCK is only usefull in multiprocessor systems, where several processors share the same resources, in particular memory. In common mode processors can access memory asyncroniuosly. So it may happen, that one processor is writing some value at the very address another one is reading from, and this may lead to some inconsistency that besides may turn out to be fatal for the code being excuted. Specially for such cases Intel's engineers introduced LOCK prefix, that locks memory bus for all other processors while the command it stays before is being executed. Thus no other command can access memory when a prefixed command is being excuted. So I think now you see what do they mean saying 'atomically'.
Serj,
Thanks for the explanation.
Rags
Another aspect of "atomicity" is preventing an interleaved access to shared resources.
Some instructions are characterized as having a read-modify-write cycle. For example, incrementing memory means read the memory, modify the value by incrementing it, then write the new value back to memory. If you are trying to count, say, a number of requests, you don't want two processors to read the same value and consequently update the counter to the same value.