SlideShare a Scribd company logo
1 of 14
SYNCHRONIZATION
HARDWARE
WHAT IS PROCESS SYNCRONIZATION.
• Process Synchronization is a way to coordinate processes that
use shared data
• Cooperating processes are processes that share resources.
• Executing many concurrent processes, process synchronization
helps to maintain shared data consistency and cooperating
process execution
• A race condition occurs when two or more operations are
executed at the same time, not scheduled in the proper
sequence, and not exited in the critical section correctly.
PROCESS SYNCHRONIZATION
• Several processes are run in operating system.
• Some of them share resources due to which problem like data
inconsistency arise
• For example :One process changing the data in memory
location where another process is trying to read the same
memory location. It is possible that the data read by the second
process will be erroneous
PROCESS
B
PROCES
SA
.
.
.
.
.
.
DATA
DATA
DATA
WRITES READS
IN PRODUCER CONSUMER PROBLEM:
(BOUNDED BUFFER PROBLEM)
The problem is to make sure that the producer won't try to add
data into the buffer if it's full and that the consumer won't try to
remove data from an empty buffer.
DATA
DATA
DATA
DATA
PRODUCE
R
CONSUME
R
A SECTION OF CODE,
• A Critical Section Environment contains:
• Entry Section Code requesting entry into
the critical section.
• Critical Section Code in which only one
process can execute at any one time.
• Exit Section The end of the critical section,
releasing or allowing others in.
• Remainder Section Rest of the code AFTER
the critical section.
THE CRITICAL SECTION MUST ENFORCE ALL
THREE OF THE FOLLOWING RULES:
• Mutual Exclusion: No more than one process can execute in its
critical section at one time.
• Progress: If no one is in the critical section and someone wants
in, then those processes not in their remainder section must be
able to decide in a finite time who should go in.
• Bounded Wait: All requesters must eventually be let into the
critical section.
WHY WE NEED HARDWARE BASE SOLUTON
• Software-based solutions such as Peterson’s are not
guaranteed to work on modern computer architectures . In the
following discussions, we explore several more solutions to the
critical-section problem.
SOLUTION TO CRITICAL-SECTION
PROBLEM USING LOCKS
do {
acquire lock
critical section
release lock
remainder section
} while (TRUE);
TESTANDSET INSTRUCTION
boolean TestAndSet (boolean *target)
{
boolean rv = *target;
*target = TRUE;
return rv:
}
SOLUTION USING TESTANDSET
• Shared boolean variable lock, initialized to FALSE
• Solution:
do {
while ( TestAndSet (&lock ))
; // do nothing
// critical section
lock = FALSE;
// remainder section
} while (TRUE);
BOUNDED-WAITING MUTUAL EXCLUSION
WITH TESTANDSET()
do {
waiting[i] = TRUE;
key = TRUE;
while (waiting[i] && key)
{
key = TestAndSet(&lock);
}
waiting[i] = FALSE;
// critical section
j = (i + 1) % n;
while ((j != i) && !waiting[ j ])
j = (j + 1) % n;
if (j == i)
lock = FALSE;
else
waiting[j] = FALSE;
// remainder section
} while (TRUE);
F F F F
F F F F
Waitin
g
Key
Lock F
1 2 3 4
BOUNDED-WAITING MUTUAL EXCLUSION
WITH TESTANDSET()
do {
waiting[i] = TRUE;
key = TRUE;
while (waiting[i] && key)
{
key = TestAndSet(&lock);
}
waiting[i] = FALSE;
// critical section
j = (i + 1) % n;
while ((j != i) && !waiting[ j ])
j = (j + 1) % n;
if (j == i)
lock = FALSE;
else
waiting[j] = FALSE;
// remainder section
} while (TRUE);
F /T F F F
F /T F F F
Waitin
g
Key
Lock F/T
1 2 3 4
SWAP INSTRUCTION
• Definition:
void Swap (boolean *a, boolean *b)
{
boolean temp = *a;
*a = *b;
*b = temp:
}
SOLUTION USING COMPARE AND SWAP
• Shared Boolean variable lock initialized to FALSE; Each process has a local Boolean variable key
• Solution:
do {
key = TRUE;
while ( key == TRUE)
{
Swap (&lock, &key );
}
// critical section
lock = FALSE;
// remainder section
} while (TRUE);

More Related Content

What's hot

File concept and access method
File concept and access methodFile concept and access method
File concept and access methodrajshreemuthiah
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating SystemsRitu Ranjan Shrivastwa
 
Operating system 32 logical versus physical address
Operating system 32 logical versus physical addressOperating system 32 logical versus physical address
Operating system 32 logical versus physical addressVaibhav Khanna
 
Process in operating system
Process in operating systemProcess in operating system
Process in operating systemChetan Mahawar
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating SystemsDr Sandeep Kumar Poonia
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
 
Process management os concept
Process management os conceptProcess management os concept
Process management os conceptpriyadeosarkar91
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionBipul Chandra Kar
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategiesDr. Loganathan R
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor schedulingShashank Kapoor
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptxRajapriya82
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memorysgpraju
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency ControlDilum Bandara
 
Classical problem of synchronization
Classical problem of synchronizationClassical problem of synchronization
Classical problem of synchronizationShakshi Ranawat
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory managementrprajat007
 

What's hot (20)

Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
File concept and access method
File concept and access methodFile concept and access method
File concept and access method
 
Disk scheduling
Disk schedulingDisk scheduling
Disk scheduling
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Memory management
Memory managementMemory management
Memory management
 
Operating system 32 logical versus physical address
Operating system 32 logical versus physical addressOperating system 32 logical versus physical address
Operating system 32 logical versus physical address
 
Process in operating system
Process in operating systemProcess in operating system
Process in operating system
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Process management os concept
Process management os conceptProcess management os concept
Process management os concept
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
 
8 memory management strategies
8 memory management strategies8 memory management strategies
8 memory management strategies
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
 
Os Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual MemoryOs Swapping, Paging, Segmentation and Virtual Memory
Os Swapping, Paging, Segmentation and Virtual Memory
 
Transactions and Concurrency Control
Transactions and Concurrency ControlTransactions and Concurrency Control
Transactions and Concurrency Control
 
Classical problem of synchronization
Classical problem of synchronizationClassical problem of synchronization
Classical problem of synchronization
 
Operating system memory management
Operating system memory managementOperating system memory management
Operating system memory management
 
Hashing
HashingHashing
Hashing
 

Similar to Synchronization hardware

Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationAnas Ebrahim
 
Process synchronization(deepa)
Process synchronization(deepa)Process synchronization(deepa)
Process synchronization(deepa)Nagarajan
 
MODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptxMODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptxsenthilkumar969017
 
Slides for OS 06-Sync.pdf
Slides for OS 06-Sync.pdfSlides for OS 06-Sync.pdf
Slides for OS 06-Sync.pdfGeekyHassan
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfAmanuelmergia
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmSouvik Roy
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxAmanuelmergia
 
Synchronization in os.pptx
Synchronization in os.pptxSynchronization in os.pptx
Synchronization in os.pptxAbdullahBhatti53
 
Operating system 23 process synchronization
Operating system 23 process synchronizationOperating system 23 process synchronization
Operating system 23 process synchronizationVaibhav Khanna
 
criticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfcriticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfBhanuCharan9
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.pptjayverma27
 
Database development unit test with tSQLt
Database development unit test with tSQLtDatabase development unit test with tSQLt
Database development unit test with tSQLtSergio Govoni
 
The Evolution of Development Testing
The Evolution of Development TestingThe Evolution of Development Testing
The Evolution of Development TestingCathal King
 

Similar to Synchronization hardware (20)

Concurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and SynchronizationConcurrency: Mutual Exclusion and Synchronization
Concurrency: Mutual Exclusion and Synchronization
 
Process synchronization(deepa)
Process synchronization(deepa)Process synchronization(deepa)
Process synchronization(deepa)
 
MODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptxMODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptx
 
Slides for OS 06-Sync.pdf
Slides for OS 06-Sync.pdfSlides for OS 06-Sync.pdf
Slides for OS 06-Sync.pdf
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdf
 
Ipc feb4
Ipc feb4Ipc feb4
Ipc feb4
 
Ch7
Ch7Ch7
Ch7
 
6 Synchronisation
6 Synchronisation6 Synchronisation
6 Synchronisation
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's Algorithm
 
Lecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptxLecture 5- Process Synchronization (1).pptx
Lecture 5- Process Synchronization (1).pptx
 
Synchronization in os.pptx
Synchronization in os.pptxSynchronization in os.pptx
Synchronization in os.pptx
 
Operating system 23 process synchronization
Operating system 23 process synchronizationOperating system 23 process synchronization
Operating system 23 process synchronization
 
Operating System
Operating SystemOperating System
Operating System
 
criticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdfcriticalsectionproblem-160905215747.pdf
criticalsectionproblem-160905215747.pdf
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
 
CH05.pdf
CH05.pdfCH05.pdf
CH05.pdf
 
Shared Memory
Shared MemoryShared Memory
Shared Memory
 
Ipc feb4
Ipc feb4Ipc feb4
Ipc feb4
 
Database development unit test with tSQLt
Database development unit test with tSQLtDatabase development unit test with tSQLt
Database development unit test with tSQLt
 
The Evolution of Development Testing
The Evolution of Development TestingThe Evolution of Development Testing
The Evolution of Development Testing
 

Recently uploaded

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Recently uploaded (20)

SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

Synchronization hardware

  • 2. WHAT IS PROCESS SYNCRONIZATION. • Process Synchronization is a way to coordinate processes that use shared data • Cooperating processes are processes that share resources. • Executing many concurrent processes, process synchronization helps to maintain shared data consistency and cooperating process execution • A race condition occurs when two or more operations are executed at the same time, not scheduled in the proper sequence, and not exited in the critical section correctly.
  • 3. PROCESS SYNCHRONIZATION • Several processes are run in operating system. • Some of them share resources due to which problem like data inconsistency arise • For example :One process changing the data in memory location where another process is trying to read the same memory location. It is possible that the data read by the second process will be erroneous PROCESS B PROCES SA . . . . . . DATA DATA DATA WRITES READS
  • 4. IN PRODUCER CONSUMER PROBLEM: (BOUNDED BUFFER PROBLEM) The problem is to make sure that the producer won't try to add data into the buffer if it's full and that the consumer won't try to remove data from an empty buffer. DATA DATA DATA DATA PRODUCE R CONSUME R
  • 5. A SECTION OF CODE, • A Critical Section Environment contains: • Entry Section Code requesting entry into the critical section. • Critical Section Code in which only one process can execute at any one time. • Exit Section The end of the critical section, releasing or allowing others in. • Remainder Section Rest of the code AFTER the critical section.
  • 6. THE CRITICAL SECTION MUST ENFORCE ALL THREE OF THE FOLLOWING RULES: • Mutual Exclusion: No more than one process can execute in its critical section at one time. • Progress: If no one is in the critical section and someone wants in, then those processes not in their remainder section must be able to decide in a finite time who should go in. • Bounded Wait: All requesters must eventually be let into the critical section.
  • 7. WHY WE NEED HARDWARE BASE SOLUTON • Software-based solutions such as Peterson’s are not guaranteed to work on modern computer architectures . In the following discussions, we explore several more solutions to the critical-section problem.
  • 8. SOLUTION TO CRITICAL-SECTION PROBLEM USING LOCKS do { acquire lock critical section release lock remainder section } while (TRUE);
  • 9. TESTANDSET INSTRUCTION boolean TestAndSet (boolean *target) { boolean rv = *target; *target = TRUE; return rv: }
  • 10. SOLUTION USING TESTANDSET • Shared boolean variable lock, initialized to FALSE • Solution: do { while ( TestAndSet (&lock )) ; // do nothing // critical section lock = FALSE; // remainder section } while (TRUE);
  • 11. BOUNDED-WAITING MUTUAL EXCLUSION WITH TESTANDSET() do { waiting[i] = TRUE; key = TRUE; while (waiting[i] && key) { key = TestAndSet(&lock); } waiting[i] = FALSE; // critical section j = (i + 1) % n; while ((j != i) && !waiting[ j ]) j = (j + 1) % n; if (j == i) lock = FALSE; else waiting[j] = FALSE; // remainder section } while (TRUE); F F F F F F F F Waitin g Key Lock F 1 2 3 4
  • 12. BOUNDED-WAITING MUTUAL EXCLUSION WITH TESTANDSET() do { waiting[i] = TRUE; key = TRUE; while (waiting[i] && key) { key = TestAndSet(&lock); } waiting[i] = FALSE; // critical section j = (i + 1) % n; while ((j != i) && !waiting[ j ]) j = (j + 1) % n; if (j == i) lock = FALSE; else waiting[j] = FALSE; // remainder section } while (TRUE); F /T F F F F /T F F F Waitin g Key Lock F/T 1 2 3 4
  • 13. SWAP INSTRUCTION • Definition: void Swap (boolean *a, boolean *b) { boolean temp = *a; *a = *b; *b = temp: }
  • 14. SOLUTION USING COMPARE AND SWAP • Shared Boolean variable lock initialized to FALSE; Each process has a local Boolean variable key • Solution: do { key = TRUE; while ( key == TRUE) { Swap (&lock, &key ); } // critical section lock = FALSE; // remainder section } while (TRUE);