News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

In programming, what does Atomically mean?

Started by rags, July 29, 2007, 10:49:01 PM

Previous topic - Next topic

rags

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
God made Man, but the monkey applied the glue -DEVO

Serj

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'.

rags

God made Man, but the monkey applied the glue -DEVO

tenkey

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.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8