wrote:
> martin griffith wrote:
>
>> Nope, not home work
>>
>> I'm still a newbie (forever), and I seen "atomic" mentioned in a few
>> threads recently
>> I've done a quick search on keil and wikipedia.
>>
>> Anyone got a simple definition ( of atomic)?
>
> An operation (usually, read-modify-write) that happens in one go and
> cannot be interrupted.
>
> A BITSET for example is usually atomic, since it is one instructions
> and cannot be interrupted.
> compare that to reading a variable in to a register ORing the bit on
> and then storing the variable again. That is _not_ atomic because
> an interrupt could get in between the intructions, potentially ending
> up with the wrong value in the register
However, on a uniprocessor system, such an operation can be made
atomic by disabling interrupts, doing the read/set/write, and then
re-enabling interrupts. This fails on a multi-processor system.
It helps if the act of disabling interrupts returns the actual
interrupt state, which can then be restored after the operation.
Then you don't have to know that interrupts were enabled before
beginning.
oldstate = disable();
/* operations to be made atomic */
enable(oldstate);
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from
http://www.teranews.com