0% found this document useful (0 votes)
2K views

Synchronization Hardware

The document discusses hardware solutions for process synchronization. It describes how hardware locks, test-and-set, swap, and lock algorithms can be used to prevent multiple processes from accessing shared resources simultaneously. Specifically, it explains that test-and-set uses a boolean variable to set a lock true when entering critical sections, while swap uses two boolean variables and a temporary variable. The lock algorithm simply acquires and releases a lock before and after critical sections.

Uploaded by

Santhosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Synchronization Hardware

The document discusses hardware solutions for process synchronization. It describes how hardware locks, test-and-set, swap, and lock algorithms can be used to prevent multiple processes from accessing shared resources simultaneously. Specifically, it explains that test-and-set uses a boolean variable to set a lock true when entering critical sections, while swap uses two boolean variables and a temporary variable. The lock algorithm simply acquires and releases a lock before and after critical sections.

Uploaded by

Santhosh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Synchronization Hardware

Overview
• Hardware Locks are used to solve the problem of process
synchronization.
• The process synchronization problem occurs when more than one
process tries to access the same resource or variable.
• If more than one process tries to update a variable at the same time
then a data inconsistency problem can occur.
• This process synchronization is also called synchronization
hardware in the operating system.
Synchronization Hardware
• Process Syncronization problem can be solved by software as well
as a hardware solution. 
• Peterson solution is one of the software solutions to the process
synchronization problem.
• Peterson algorithm allows two or more processes to share a single-
use resource without any conflict.
• The hardware solution is as follows:
• Test and set
• Swap and unlock
• lock algorithm
Test and Set
Test and Set
boolean lock = false;
boolean TestAndSet(boolean target){
boolean returnValue = target;
target = true;
return returnValue;
}
Do
{
while(TestAndSet(lock));
CRITICAL SECTION CODE;
lock = false;
REMAINDER SECTION CODE;
}
Swap Function
• Swap function uses two boolean variables lock and key.
• Both lock and key variables are initially initialized to false. 
• Swap algorithm is the same as lock and set algorithm.
• The Swap algorithm uses a temporary variable to set the lock to true
when a process enters the critical section of the program.
Swap
boolean lock = false;
individual key = false;
void swap(boolean &a, boolean &b){
boolean temp = a;
a = b;
b = temp;
}
do{
key=true;
while(key){
swap(lock,key);
}
CRITICAL SECTION CODE
lock = false;
REMAINDER SECTION CODE
}
Lock Algorithm
• One of the oldest methodologies
• It can be implemented for many processes
Do
{
Acquire(lock);
Critical Section;
Release(lock);
}
Lock algorithm
While (lock==1);
Lock=1;
Critical section
Lock=0;
Peterson’s solution

You might also like