Link to home
Start Free TrialLog in
Avatar of naseeam
naseeamFlag for United States of America

asked on

What is atomic operation?

In every professional embedded 'C' code, there are atomic operations and interrupts are disabled during execution of atomic operations.

Please provide several examples of atomic operations and why interrupts need to be disabled during execution of atomic operations?
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

An atomic operation is one that needs to complete without interruption. The atomicity may be guaranteed or it may be a requirement of an operation. In the case where it is a requirement it will be necessary to ensure interrupts are disabled such that they cannot interrupt the execution of the atomic operation.
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of naseeam

ASKER

Above says "another task", Does this mean when interrupts are disabled, tasks are automatically disabled ?


Also, the only reason interrupts are disabled during atomic operations is to prevent ISR or another task from duplicating execution of atomic instructions ?
For this discussion, I probably should have used the term "thread".  That's where atomic operations are most common, but it can also apply to tasks with shared memory.

It can be quite a bit more complicated than simply preventing duplication of atomic instructions.  Imagine what the operating system must go through for simple disk operations.  You can have multiple threads or tasks trying to simultaneously perform read and write operation on the same device.  If two tasks are trying to simultaneously extend different files on the same device, the O/S must ensure isolation of the operations while also allowing other tasks to read data that relies on the same cluster/track/sector chains as one of the files being written.  The O/S goes through significant hoops to maintain the integrity of the disk structure in a way that allows nearly simultaneous access to other data on the device instead of just locking clusters.  Atomic operations on granular locks are one of the techniques that can be used.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of naseeam

ASKER

Helpful examples