/    /  OS – Synchronization Hardware

Synchronization Hardware

 

Process Synchronization refers to coordinating the execution of processes so that no two processes can have access to the same shared data and resources. A problem occurs when two processes running simultaneously share the same data or variable.

There are three hardware approaches to solve process synchronization problems:

  1. Swap
  2. Test() and Set() 
  3. Unlock and lock

Test and Set

In Test and Set the shared variable is a lock that is initialized to false. 

The algorithm returns whatever value is sent to it and sets the lock to true. Mutual exclusion is ensured here, as till the lock is set to true, other processes will not be able to enter and the loop continues.

However, after one process is completed any other process can go in as no queue is maintained. 

Swap

In this algorithm, instead of directly setting the lock to true, the key is first set to true and then swapped with the lock. 

Similar to Test and Set, when there are no processes in the critical section, the lock turns to false and allows other processes to enter. Hence, mutual exclusion and progress are ensured but the bound waiting is not ensured for the very same reason.

Unlock and Lock

In addition to Test and Set, this algorithm uses waiting[i] to check if there are any processes in the wait. The processes are set in the ready queue with respect to the critical section. 

Unlike the previous algorithms, it doesn’t set the lock to false and checks the ready queue for any waiting processes. If there are no processes waiting in the ready queue, the lock is then set to false and any process can enter. 

Reference

Synchronization Hardware