Atomic Operations in OS
Atomic operations are the operations that execute as a single unified operation. In simple terms, when an atomic operation is being executed, no other process can read through or modify the data that is currently used by atomic operation.
Atomic operations are used in concurrent programming where program operations run independently, without being interleaved by any other operation. These operations are used in many operating systems which implements parallel processing.
Type of Atomic Operations
Listed below are some of the atomic operations which are being used regularly:
- Fine-grained atomic operations: These operations can be implemented without any interruptions. For example, loading and storing registers.
- Coarse-grained atomic operations: These include a series of fine-grained operations which cannot be interrupted. For example a call of a synchronized method in JAVA.
Advantage and Disadvantage of Atomic Operations
Atomic operations are usually faster when compared to locks. Also, they do not suffer from issues of deadlocks and convoying.
One restraining factor of atomic operations is that they only execute a limited number of processes and cannot function efficiently when complicated processes are to be executed.
Example of Atomic Operation
Consider a process in which the value of temp is to be fetched and incremented by 1. Let initially, the value of temp be 0. Now after the execution of the process the value of temp is increased by 1 and it becomes equal to 1. However, now this processes is pre-empted and a new process is initiated, which also use the value of temp and increase its value by 5. Now, the value of temp becomes 6 as the initial value was 1, which is then increased by 5. After, completion of this process, when the first process starts its execution again, the value of temp becomes 5+1=6. However, the expected result, in this case, was 1+1=2. Hence, a wrong solution is generated.
Nevertheless, in the case of atomic operations, the value of temp can neither be read nor modified, thereby ensuring the accuracy of results.
- Process Synchronization
- Critical Section
- Inter-Process Communication
- UEFI(Unified Extensible Firmware Interface) and how is it different from BIOS
- Mutex vs. Semaphore
- Atomic Operations in OS
- Peterson’s Algorithm for Mutual Exclusion (Only important for Cisco and Arista Networs)
- Peterson’s Algorithm for Critical Section Problem (Only important for Cisco and Arista Networs)
- Readers-Writers Problem