SlideShare a Scribd company logo
Lecture 11: Synchronization
(Chapter 6, cont)

Operating System Concepts – 8 th Edition,

Silberschatz, Galvin and Gagne
Semaphores (by Dijkstra 1930 – 2002)
Born in Rotterdam, The Netherlands
1972 recipient of the ACM Turing Award
Responsible for
The idea of building operating systems as explicitly
synchronized sequential processes
The formal development of computer programs
Best known for
His efficient shortest path algorithm
Having designed and coded the first Algol 60 compiler.
Famous campaign for the abolition of the GOTO statement
Also known for his hand-written communications with friends
and colleagues. For example:
http://www.cs.utexas.edu/users/EWD/ewd12xx/EWD1205.PDF
Operating System Concepts – 8 th Edition

6.2

Silberschatz, Galvin and Gagne
Semaphores
Synchronization tool that does not require busy waiting
Semaphore S – integer variable
Two standard operations modify S: wait() and signal()
Originally called P() and V()
Also called down() and up()
The value of S can only be accessed through wait()
and signal()
wait (S) {

signal (S) {

while S <= 0

S++;

; // no-op

}

S--;
}
Operating System Concepts – 8 th Edition

6.3

Silberschatz, Galvin and Gagne
Semaphore Implementation with no Busy waiting

With each semaphore there is an associated waiting
queue.
typedef struct{
tnt value;
struct process *list;
} semaphore;
Two operations on processes:
block – place the process invoking the operation on
the appropriate waiting queue.
wakeup – remove one of processes in the waiting
queue and place it in the ready queue.

Operating System Concepts – 8 th Edition

6.4

Silberschatz, Galvin and Gagne
Semaphore Implementation with no Busy waiting (Cont.)
Implementation of wait:
wait(semaphore *S) {
S->value--;
if (S->value < 0) {
add this process to S->list;
block();
}
}
Implementation of signal:
signal(semaphore *S) {
S->value++;
if (S->value <= 0) {
remove a process P from S->list;
wakeup(P);
}
Silberschatz, Galvin and Gagne
6.5
Operating System Concepts – 8 Edition
}
th
Semaphore as General Synchronization Tool
Counting semaphore – integer value can range over an unrestricted domain
Binary semaphore – integer value can range only between 0
and 1; can be simpler to implement
Also known as mutex locks
Can implement a counting semaphore S as a binary semaphore
Provides mutual exclusion
Semaphore mutex;

// initialized to 1

do {
wait (mutex);
// Critical Section
signal (mutex);
// remainder section
} while (TRUE);

Operating System Concepts – 8 th Edition

6.6

Silberschatz, Galvin and Gagne
Group Work (1): Signaling
One thread sends a signal to another
thread to indicate that something has
happened

Operating System Concepts – 8 th Edition

6.7

Silberschatz, Galvin and Gagne
Group Work (2): rendezvous
Generalize the signal pattern so that it works
both ways: Thread A has to wait for
Thread B and vice versa.

Thread A
a1
a2

Thread B
b1
b2

we want to guarantee that a1 happens before b2
and b1 happens before a2

Operating System Concepts – 8 th Edition

6.8

Silberschatz, Galvin and Gagne
Deadlock and Starvation
Deadlock – two or more processes are waiting indefinitely for an
event that can be caused by only one of the waiting processes
Let S and Q be two semaphores initialized to 1
P0
P1
wait (S);

wait (Q);

wait (Q);

wait (S);

.

.

.

.

.

.

signal (S);

signal (Q);

signal (Q);

signal (S);

Starvation – indefinite blocking. A process may never be removed
from the semaphore queue in which it is suspended
Priority Inversion - Scheduling problem when lower-priority process
holds a lock needed by higher-priority process
Operating System Concepts – 8 th Edition

6.9

Silberschatz, Galvin and Gagne
Classical Problems of Synchronization
Bounded-Buffer Problem
Readers and Writers Problem
Dining-Philosophers Problem

Operating System Concepts – 8 th Edition

6.10

Silberschatz, Galvin and Gagne
Bounded-Buffer Problem
N buffers, each can hold one item
Semaphore mutex initialized to 1
Semaphore full initialized to 0
Semaphore empty initialized to N.

Operating System Concepts – 8 th Edition

6.11

Silberschatz, Galvin and Gagne
Bounded Buffer Solution
Producer:

Consumer:

do {

do {
// produce an item in nextp

wait (full);
wait (mutex);

wait (empty);
wait (mutex);

// remove an item from buffer to nextc

// add the item to the buffer

signal (mutex);
signal (empty);

signal (mutex);
signal (full);

// consume the item in nextc

} while (TRUE);
} while (TRUE);
Operating System Concepts – 8 th Edition

6.12

Silberschatz, Galvin and Gagne
Readers-Writers Problem
A data set is shared among a number of concurrent
processes
Readers – only read; they do not perform any updates
Writers – can both read and write

Problem:
Allow multiple readers to read at the same time.
Only one writer can access the shared data at the same time

Shared Data
Data set
Semaphore mutex initialized to 1
Semaphore wrt initialized to 1
Integer readcount initialized to 0
Operating System Concepts – 8 th Edition

6.13

Silberschatz, Galvin and Gagne
Readers-Writers Solution
Reader:

Writer:

do {

do {

wait (mutex) ;
readcount ++ ;
if (readcount == 1)
wait (wrt) ;
signal (mutex)

wait (wrt) ;
//

writing is performed
signal (wrt) ;

// reading is performed

} while (TRUE);
wait (mutex) ;
readcount - - ;
if (readcount == 0)
signal (wrt) ;
signal (mutex) ;
} while (TRUE);
Operating System Concepts – 8 th Edition

6.14

Silberschatz, Galvin and Gagne
Same Solution in Different Format

Operating System Concepts – 8 th Edition

6.15

Silberschatz, Galvin and Gagne
Version 2 (part 1)

Operating System Concepts – 8 th Edition

6.16

Silberschatz, Galvin and Gagne
Version 2 (part 2)

Operating System Concepts – 8 th Edition

6.17

Silberschatz, Galvin and Gagne
Dining Philosophers Problem

Operating System Concepts – 8 th Edition

6.18

Silberschatz, Galvin and Gagne
The Problem
Devise a ritual (algorithm) that will allow
the philosophers to eat.
No two philosophers can use the same fork at
the same time (mutual exclusion)
No philosopher must starve to death (avoid
deadlock and starvation … literally!)

Operating System Concepts – 8 th Edition

6.19

Silberschatz, Galvin and Gagne
What's Wrong?

Operating System Concepts – 8 th Edition

6.20

Silberschatz, Galvin and Gagne
Avoiding deadlock (only 4 philosophers)

Operating System Concepts – 8 th Edition

6.21

Silberschatz, Galvin and Gagne
Dining Philosophers: Solution

Operating System Concepts – 8 th Edition

6.22

Silberschatz, Galvin and Gagne
Operating System Concepts – 8 th Edition

6.23

Silberschatz, Galvin and Gagne

More Related Content

What's hot

Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
MOHIT DADU
 
Os Threads
Os ThreadsOs Threads
Os Threads
Salman Memon
 
Semaphores
SemaphoresSemaphores
Semaphores
Mohd Arif
 
Chapter 10 Operating Systems silberschatz
Chapter 10 Operating Systems silberschatzChapter 10 Operating Systems silberschatz
Chapter 10 Operating Systems silberschatz
GiulianoRanauro
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"
Ra'Fat Al-Msie'deen
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
Wayne Jones Jnr
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
Ravindra Raju Kolahalam
 
Monitors
MonitorsMonitors
Monitors
Mohd Arif
 
Mca ii os u-1 introduction to os
Mca  ii  os u-1 introduction to osMca  ii  os u-1 introduction to os
Mca ii os u-1 introduction to os
Rai University
 
12 process control blocks
12 process control blocks12 process control blocks
12 process control blocks
myrajendra
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
sangrampatil81
 
Ipc in linux
Ipc in linuxIpc in linux
Ipc in linux
Dr. C.V. Suresh Babu
 
Mutual exclusion and sync
Mutual exclusion and syncMutual exclusion and sync
Mutual exclusion and sync
Dr. C.V. Suresh Babu
 
Unix case-study
Unix case-studyUnix case-study
Unix case-study
NishantMishra126
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
sgpraju
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
vampugani
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
Mukesh Chinta
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
Khushboo Jain
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
Ra'Fat Al-Msie'deen
 
Process management in os
Process management in osProcess management in os
Process management in os
Miong Lazaro
 

What's hot (20)

Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
 
Os Threads
Os ThreadsOs Threads
Os Threads
 
Semaphores
SemaphoresSemaphores
Semaphores
 
Chapter 10 Operating Systems silberschatz
Chapter 10 Operating Systems silberschatzChapter 10 Operating Systems silberschatz
Chapter 10 Operating Systems silberschatz
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 
Monitors
MonitorsMonitors
Monitors
 
Mca ii os u-1 introduction to os
Mca  ii  os u-1 introduction to osMca  ii  os u-1 introduction to os
Mca ii os u-1 introduction to os
 
12 process control blocks
12 process control blocks12 process control blocks
12 process control blocks
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Ipc in linux
Ipc in linuxIpc in linux
Ipc in linux
 
Mutual exclusion and sync
Mutual exclusion and syncMutual exclusion and sync
Mutual exclusion and sync
 
Unix case-study
Unix case-studyUnix case-study
Unix case-study
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
Process state in OS
Process state in OSProcess state in OS
Process state in OS
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
 
Process management in os
Process management in osProcess management in os
Process management in os
 

Viewers also liked

Semaphores OS Basics
Semaphores OS BasicsSemaphores OS Basics
Semaphores OS Basics
Shijin Raj P
 
Semaphore
SemaphoreSemaphore
Semaphore
naniix21_3
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
Bipul Chandra Kar
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
Ritu Ranjan Shrivastwa
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
Wayne Jones Jnr
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
Sonali Chauhan
 
Producer consumer
Producer consumerProducer consumer
Producer consumer
Mohd Tousif
 
Offshore Software Development Company
Offshore Software Development CompanyOffshore Software Development Company
Offshore Software Development Company
will123
 
Operating Systems - Advanced Synchronization
Operating Systems - Advanced SynchronizationOperating Systems - Advanced Synchronization
Operating Systems - Advanced Synchronization
Emery Berger
 
Producer Consumer Problem
Producer Consumer Problem  Producer Consumer Problem
Producer Consumer Problem
Mohamed Abd-elmotty
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
Harshana Madusanka Jayamaha
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
Wayne Jones Jnr
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
C.U
 
ITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded bufferITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded buffer
Sneh Prabha
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
Harshith Meela
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
Vaibhav Bajaj
 
Operating system overview concepts ppt
Operating system overview concepts pptOperating system overview concepts ppt
Operating system overview concepts ppt
RajendraPrasad Alladi
 
Linux Operating system : Thrashing and Remedy
Linux Operating system : Thrashing and Remedy Linux Operating system : Thrashing and Remedy
Linux Operating system : Thrashing and Remedy
Ahsen Saeed
 
Ch05
Ch05Ch05
Ch4 Threads
Ch4 ThreadsCh4 Threads
Ch4 Threads
mayacendana
 

Viewers also liked (20)

Semaphores OS Basics
Semaphores OS BasicsSemaphores OS Basics
Semaphores OS Basics
 
Semaphore
SemaphoreSemaphore
Semaphore
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
Producer consumer
Producer consumerProducer consumer
Producer consumer
 
Offshore Software Development Company
Offshore Software Development CompanyOffshore Software Development Company
Offshore Software Development Company
 
Operating Systems - Advanced Synchronization
Operating Systems - Advanced SynchronizationOperating Systems - Advanced Synchronization
Operating Systems - Advanced Synchronization
 
Producer Consumer Problem
Producer Consumer Problem  Producer Consumer Problem
Producer Consumer Problem
 
Operating system critical section
Operating system   critical sectionOperating system   critical section
Operating system critical section
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 
ITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded bufferITFT_Semaphores and bounded buffer
ITFT_Semaphores and bounded buffer
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
Operating system.ppt (1)
Operating system.ppt (1)Operating system.ppt (1)
Operating system.ppt (1)
 
Operating system overview concepts ppt
Operating system overview concepts pptOperating system overview concepts ppt
Operating system overview concepts ppt
 
Linux Operating system : Thrashing and Remedy
Linux Operating system : Thrashing and Remedy Linux Operating system : Thrashing and Remedy
Linux Operating system : Thrashing and Remedy
 
Ch05
Ch05Ch05
Ch05
 
Ch4 Threads
Ch4 ThreadsCh4 Threads
Ch4 Threads
 

Similar to Lec11 semaphores

Chapter 6
Chapter 6Chapter 6
Chapter 6
Ahmad Alarbeed
 
chapter4.pptx
chapter4.pptxchapter4.pptx
chapter4.pptx
alisou77666
 
PS.ppt
PS.pptPS.ppt
6.Process Synchronization
6.Process Synchronization6.Process Synchronization
6.Process Synchronization
Senthil Kanth
 
Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )
HimanshuSharma1389
 
05-Process-Synchronization.pdf
05-Process-Synchronization.pdf05-Process-Synchronization.pdf
05-Process-Synchronization.pdf
milisjojo
 
Process Synchronisation Operating System
Process Synchronisation Operating SystemProcess Synchronisation Operating System
Process Synchronisation Operating System
DRAnithaSofiaLizCSES
 
process synchronisation operating system
process synchronisation operating systemprocess synchronisation operating system
process synchronisation operating system
codefast
 
تعليم البرمجه.pdf
تعليم البرمجه.pdfتعليم البرمجه.pdf
تعليم البرمجه.pdf
ssuser893014
 
ch6-1.ppt
ch6-1.pptch6-1.ppt
ch6-1.ppt
ssuserc35fa4
 
5 process synchronization
5 process synchronization5 process synchronization
5 process synchronization
BaliThorat1
 
Mca ii os u-2 process management & communication
Mca  ii  os u-2 process management & communicationMca  ii  os u-2 process management & communication
Mca ii os u-2 process management & communication
Rai University
 
ch5 [Autosaved].ppt
ch5 [Autosaved].pptch5 [Autosaved].ppt
ch5 [Autosaved].ppt
monirJihad2
 
ch05.ppt
ch05.pptch05.ppt
ch05.ppt
RohitPaul71
 
Operating System-Process Synchronization
Operating System-Process SynchronizationOperating System-Process Synchronization
Operating System-Process Synchronization
bismahmalik22
 
Lecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdf
Lecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdf
Lecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdf
mohammedabomashowrms
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
vijay974055
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
karinaabyys
 
chapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio pptchapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio ppt
Abdikani34
 
ch5-Process_Synchronization.pdf
ch5-Process_Synchronization.pdfch5-Process_Synchronization.pdf
ch5-Process_Synchronization.pdf
sharada3
 

Similar to Lec11 semaphores (20)

Chapter 6
Chapter 6Chapter 6
Chapter 6
 
chapter4.pptx
chapter4.pptxchapter4.pptx
chapter4.pptx
 
PS.ppt
PS.pptPS.ppt
PS.ppt
 
6.Process Synchronization
6.Process Synchronization6.Process Synchronization
6.Process Synchronization
 
Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )
 
05-Process-Synchronization.pdf
05-Process-Synchronization.pdf05-Process-Synchronization.pdf
05-Process-Synchronization.pdf
 
Process Synchronisation Operating System
Process Synchronisation Operating SystemProcess Synchronisation Operating System
Process Synchronisation Operating System
 
process synchronisation operating system
process synchronisation operating systemprocess synchronisation operating system
process synchronisation operating system
 
تعليم البرمجه.pdf
تعليم البرمجه.pdfتعليم البرمجه.pdf
تعليم البرمجه.pdf
 
ch6-1.ppt
ch6-1.pptch6-1.ppt
ch6-1.ppt
 
5 process synchronization
5 process synchronization5 process synchronization
5 process synchronization
 
Mca ii os u-2 process management & communication
Mca  ii  os u-2 process management & communicationMca  ii  os u-2 process management & communication
Mca ii os u-2 process management & communication
 
ch5 [Autosaved].ppt
ch5 [Autosaved].pptch5 [Autosaved].ppt
ch5 [Autosaved].ppt
 
ch05.ppt
ch05.pptch05.ppt
ch05.ppt
 
Operating System-Process Synchronization
Operating System-Process SynchronizationOperating System-Process Synchronization
Operating System-Process Synchronization
 
Lecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdf
Lecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdf
Lecture 9.pdfLecture 9.pdfLecture 9.pdfLecture 9.pdf
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
 
chapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio pptchapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio ppt
 
ch5-Process_Synchronization.pdf
ch5-Process_Synchronization.pdfch5-Process_Synchronization.pdf
ch5-Process_Synchronization.pdf
 

Recently uploaded

Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
Ivanti
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 

Recently uploaded (20)

Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
June Patch Tuesday
June Patch TuesdayJune Patch Tuesday
June Patch Tuesday
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 

Lec11 semaphores

  • 1. Lecture 11: Synchronization (Chapter 6, cont) Operating System Concepts – 8 th Edition, Silberschatz, Galvin and Gagne
  • 2. Semaphores (by Dijkstra 1930 – 2002) Born in Rotterdam, The Netherlands 1972 recipient of the ACM Turing Award Responsible for The idea of building operating systems as explicitly synchronized sequential processes The formal development of computer programs Best known for His efficient shortest path algorithm Having designed and coded the first Algol 60 compiler. Famous campaign for the abolition of the GOTO statement Also known for his hand-written communications with friends and colleagues. For example: http://www.cs.utexas.edu/users/EWD/ewd12xx/EWD1205.PDF Operating System Concepts – 8 th Edition 6.2 Silberschatz, Galvin and Gagne
  • 3. Semaphores Synchronization tool that does not require busy waiting Semaphore S – integer variable Two standard operations modify S: wait() and signal() Originally called P() and V() Also called down() and up() The value of S can only be accessed through wait() and signal() wait (S) { signal (S) { while S <= 0 S++; ; // no-op } S--; } Operating System Concepts – 8 th Edition 6.3 Silberschatz, Galvin and Gagne
  • 4. Semaphore Implementation with no Busy waiting With each semaphore there is an associated waiting queue. typedef struct{ tnt value; struct process *list; } semaphore; Two operations on processes: block – place the process invoking the operation on the appropriate waiting queue. wakeup – remove one of processes in the waiting queue and place it in the ready queue. Operating System Concepts – 8 th Edition 6.4 Silberschatz, Galvin and Gagne
  • 5. Semaphore Implementation with no Busy waiting (Cont.) Implementation of wait: wait(semaphore *S) { S->value--; if (S->value < 0) { add this process to S->list; block(); } } Implementation of signal: signal(semaphore *S) { S->value++; if (S->value <= 0) { remove a process P from S->list; wakeup(P); } Silberschatz, Galvin and Gagne 6.5 Operating System Concepts – 8 Edition } th
  • 6. Semaphore as General Synchronization Tool Counting semaphore – integer value can range over an unrestricted domain Binary semaphore – integer value can range only between 0 and 1; can be simpler to implement Also known as mutex locks Can implement a counting semaphore S as a binary semaphore Provides mutual exclusion Semaphore mutex; // initialized to 1 do { wait (mutex); // Critical Section signal (mutex); // remainder section } while (TRUE); Operating System Concepts – 8 th Edition 6.6 Silberschatz, Galvin and Gagne
  • 7. Group Work (1): Signaling One thread sends a signal to another thread to indicate that something has happened Operating System Concepts – 8 th Edition 6.7 Silberschatz, Galvin and Gagne
  • 8. Group Work (2): rendezvous Generalize the signal pattern so that it works both ways: Thread A has to wait for Thread B and vice versa. Thread A a1 a2 Thread B b1 b2 we want to guarantee that a1 happens before b2 and b1 happens before a2 Operating System Concepts – 8 th Edition 6.8 Silberschatz, Galvin and Gagne
  • 9. Deadlock and Starvation Deadlock – two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes Let S and Q be two semaphores initialized to 1 P0 P1 wait (S); wait (Q); wait (Q); wait (S); . . . . . . signal (S); signal (Q); signal (Q); signal (S); Starvation – indefinite blocking. A process may never be removed from the semaphore queue in which it is suspended Priority Inversion - Scheduling problem when lower-priority process holds a lock needed by higher-priority process Operating System Concepts – 8 th Edition 6.9 Silberschatz, Galvin and Gagne
  • 10. Classical Problems of Synchronization Bounded-Buffer Problem Readers and Writers Problem Dining-Philosophers Problem Operating System Concepts – 8 th Edition 6.10 Silberschatz, Galvin and Gagne
  • 11. Bounded-Buffer Problem N buffers, each can hold one item Semaphore mutex initialized to 1 Semaphore full initialized to 0 Semaphore empty initialized to N. Operating System Concepts – 8 th Edition 6.11 Silberschatz, Galvin and Gagne
  • 12. Bounded Buffer Solution Producer: Consumer: do { do { // produce an item in nextp wait (full); wait (mutex); wait (empty); wait (mutex); // remove an item from buffer to nextc // add the item to the buffer signal (mutex); signal (empty); signal (mutex); signal (full); // consume the item in nextc } while (TRUE); } while (TRUE); Operating System Concepts – 8 th Edition 6.12 Silberschatz, Galvin and Gagne
  • 13. Readers-Writers Problem A data set is shared among a number of concurrent processes Readers – only read; they do not perform any updates Writers – can both read and write Problem: Allow multiple readers to read at the same time. Only one writer can access the shared data at the same time Shared Data Data set Semaphore mutex initialized to 1 Semaphore wrt initialized to 1 Integer readcount initialized to 0 Operating System Concepts – 8 th Edition 6.13 Silberschatz, Galvin and Gagne
  • 14. Readers-Writers Solution Reader: Writer: do { do { wait (mutex) ; readcount ++ ; if (readcount == 1) wait (wrt) ; signal (mutex) wait (wrt) ; // writing is performed signal (wrt) ; // reading is performed } while (TRUE); wait (mutex) ; readcount - - ; if (readcount == 0) signal (wrt) ; signal (mutex) ; } while (TRUE); Operating System Concepts – 8 th Edition 6.14 Silberschatz, Galvin and Gagne
  • 15. Same Solution in Different Format Operating System Concepts – 8 th Edition 6.15 Silberschatz, Galvin and Gagne
  • 16. Version 2 (part 1) Operating System Concepts – 8 th Edition 6.16 Silberschatz, Galvin and Gagne
  • 17. Version 2 (part 2) Operating System Concepts – 8 th Edition 6.17 Silberschatz, Galvin and Gagne
  • 18. Dining Philosophers Problem Operating System Concepts – 8 th Edition 6.18 Silberschatz, Galvin and Gagne
  • 19. The Problem Devise a ritual (algorithm) that will allow the philosophers to eat. No two philosophers can use the same fork at the same time (mutual exclusion) No philosopher must starve to death (avoid deadlock and starvation … literally!) Operating System Concepts – 8 th Edition 6.19 Silberschatz, Galvin and Gagne
  • 20. What's Wrong? Operating System Concepts – 8 th Edition 6.20 Silberschatz, Galvin and Gagne
  • 21. Avoiding deadlock (only 4 philosophers) Operating System Concepts – 8 th Edition 6.21 Silberschatz, Galvin and Gagne
  • 22. Dining Philosophers: Solution Operating System Concepts – 8 th Edition 6.22 Silberschatz, Galvin and Gagne
  • 23. Operating System Concepts – 8 th Edition 6.23 Silberschatz, Galvin and Gagne

Editor's Notes

  1. This solution uses semaphores, showing one instance each of a reader and a writer; the solution does not change for multiple readers and writers. Once a single reader has begun to access the data area, it is possible for readers to retain control of the data area as long as there is at least one reader in the act of reading. Therefore, writers are subject to starvation.
  2. This solution guarantees that no new readers are allowed access to the data area once at least one writer has declared a desire to write. Continued on next slide
  3. Five philosophers live in a house, where a table is laid for them. The life of each philosopher consists principally of thinking and eating, and through years of thought, all of the philosophers had agreed that the only food that contributed to their thinking efforts was spaghetti. Due to a lack of manual skill, each philosopher requires two forks to eat spaghetti. A philosopher wishing to eat goes to his or her assigned place at the table and, using the two forks on either side of the plate, takes and eats some spaghetti.
  4. Each philosopher picks up first the fork on the left and then the fork on the right. After the philosopher is finished eating, the two forks are replaced on the table. This solution, alas, leads to deadlock: If all of the philosophers are hungry at the same time, they all sit down, they all pick up the fork on their left, and they all reach out for the other fork, which is not there. In this undignified position, all philosophers starve.
  5. We could consider adding an attendant who only allows four philosophers at a time into the dining room. With at most four seated philosophers, at least one philosopher will have access to two forks. This slide shows such a solution, again using semaphores. This solution is free of deadlock and starvation.