SlideShare a Scribd company logo
1 of 50
Rushdi Shams, Dept of CSE, KUET 1
Operating SystemsOperating Systems
Inter-processInter-process CommunicationCommunication
Version 1.0
Rushdi Shams, Dept of CSE, KUET 2
IPC
One process, sometimes, require the output of other
process
Therefore, there is a need of well structured
communication among processes.
Not preferring interrupts to draw attention.
Rushdi Shams, Dept of CSE, KUET 3
IPC
 Three issues in IPC-
1. How one process can pass information to another
2. Making sure that two or more processes do not get
into each other’s way when engaging in critical
activities (both wants last 1 MB space of virtual
memory)
3. Proper sequencing when dependency is present (if A
produces data that B prints, then B cannot print
unless A is producing some data)
Rushdi Shams, Dept of CSE, KUET 4
Inter-thread Communication
 In case of ITC, the same issues are concerns.
 The first one is not a headache as threads share
some common resources and address space; so, they
can easily communicate
 But the other twos are issues in ITC as well.
Rushdi Shams, Dept of CSE, KUET 5
Race Condition
A process wants to print a file.
It enters the file name in a special printer directory
The Printer Daemon periodically checks to see if
there is any file to print
If any file is there the Printer Daemon prints them
and removes their names from the directory
Rushdi Shams, Dept of CSE, KUET 6
Race Condition
Imagine our directory has a very large number of slots
(numbered 0,1,2,…) and each one can hold a file name
There are two shared variables- out that points to the
next file to be printed and in that points to the next
free slot in the directory
Rushdi Shams, Dept of CSE, KUET 7
Race Condition
Rushdi Shams, Dept of CSE, KUET 8
Race Condition
A reads in and stores the
values 7 to its local variable
Then a context switch from A
to B occurs
B also reads in and stores the
value 7 to its local variable
B continues to run and it
stores the name of its file in
slot 7 and updates in to 8.
Then it goes off and does
other things
Rushdi Shams, Dept of CSE, KUET 9
Race Condition
A runs again starting from
the place it left off
It looks its local variable and
finds 7 there and writes the
file name in slot 7
Then A sets in to 8
As everything went fine, the
printer daemon will not raise
any error
Rushdi Shams, Dept of CSE, KUET 10
Race Condition
Process B never gets the chance
Situations like this where two or more processes are
reading or writing some shared data and the final
result depends on who ran precisely are called race
conditions
Rushdi Shams, Dept of CSE, KUET 11
Critical Regions
How can we avoid race conditions?
One way to avoid that is prohibiting more than one
process from reading and writing the shared data at
the same time
This is called Mutual Exclusion
Rushdi Shams, Dept of CSE, KUET 12
Critical Regions
On the other hand, let’s think in abstract way.
A process is busy doing internal computations and
other things that do not lead race conditions
And sometimes it is busy to access shared memory
and files or in doing other critical things that lead
race conditions
The part of the program where shared memory or
resources are accesses is called Critical Regions
Rushdi Shams, Dept of CSE, KUET 13
Critical Regions
 We need four conditions to hold for a good
solution with mutual exclusion-
1. No two processes simultaneously in critical region
2. No assumptions made about speeds or numbers of
CPUs
3. No process running outside its critical region may
block another process
4. No process must wait forever to enter its critical
region
Rushdi Shams, Dept of CSE, KUET 14
Mutual Exclusion with Critical
Regions
Rushdi Shams, Dept of CSE, KUET 15
How can we achieve mutual
exclusion?
Now, let’s examine various proposals to achieve
mutual exclusion
While one process is busy to update shared memory
in its critical region, no other process will enter its
critical region and cause trouble
Rushdi Shams, Dept of CSE, KUET 16
Disabling Interrupts
When a process enters into its critical region, it
disables all interrupts
While leaving its critical region, it re-enables all
interrupts
Unattractive and unwise to give user processes the
power of turning off interrupts. What if one of them
did it and never turned them on again!! 
That is the end of the system!!! 
It is often useful technique within the OS itself but
not suitable as a general mutual exclusion mechanism
Rushdi Shams, Dept of CSE, KUET 17
Lock Variables
It’s a software solution
When a process wants to enter into the critical
region, it checks the lock variable
If it is 0, the process sets it to 1 and enters into its
critical region
If it is 1, the process waits
Rushdi Shams, Dept of CSE, KUET 18
Lock Variables
One process reads the lock and sees 0
Before it sets 1, another process is scheduled, runs
and sets the lock 1
When the first process runs, it will also set the lock 1
Two processes will be in their critical regions in the
same time.
Rushdi Shams, Dept of CSE, KUET 19
Strict Alternation
turn is a variable initially 0 keeps track of whose turn it is to
enter critical regions
Process 0 inspects turn and finds 0 and enters into its critical
region
Process 1 finds turn to be 0 and continuously tests the value of
turn
Continuously testing a variable until some value appears is
called Busy Waiting
Rushdi Shams, Dept of CSE, KUET 20
Strict Alternation
It should usually be avoided as it wastes CPU
time
Can be useful when short busy waiting is
probable
Requires strict alternating process to provide
better result
Inefficient when one process is much slower
than the other
Rushdi Shams, Dept of CSE, KUET 21
Peterson’s Solution
Rushdi Shams, Dept of CSE, KUET 22
 So far, the techniques we learnt (except disabling
interrupts)-
1. Lock variables
2. Strict Alternation
3. Peterson’s Solution
To achieve mutual exclusion, all have a common
problem- Busy Waiting
 In case of prioritized scheduling, low prioritized
processes will never be fed if Busy Waiting takes
place
Rushdi Shams, Dept of CSE, KUET 23
Different Mechanisms with Sleep
and Wake
Now, we will see more mechanisms to achieve mutual
exclusion
These techniques will use Sleep and Wake- two
system calls
Sleep causes a process to be suspended until another
process wakes it up
Wake causes a process to wake up
Rushdi Shams, Dept of CSE, KUET 24
The Producer-Consumer Problem
When the producer sees a full buffer and goes to
sleep. When the consumer takes out an item, it
awakes the producer
When the consumer sees an empty buffer and goes to
sleep. When the producer puts an item, it awakes the
consumer
Rushdi Shams, Dept of CSE, KUET 25
The Producer-Consumer Problem
We will use count as a variable to stop race
conditions
If the maximum no of information the buffer stores in
N, then producer first checks if count = N. If yes, then
it sleeps; otherwise it will add an item and increment
count by 1
The consumer tests count. If count = 0, then it sleeps;
otherwise it removes an information and decrements
count by 1
Rushdi Shams, Dept of CSE, KUET 26
The Producer-Consumer Problem
Rushdi Shams, Dept of CSE, KUET 27
The Producer-Consumer Problem
 Two processes share a common, fixed-sized buffer
 The producer puts information into the buffer
 The consumer takes it out
 Problem arises when-
1. Producer wants to put information into a buffer that
is full
2. Consumer wants to get information from a buffer
that is empty
Rushdi Shams, Dept of CSE, KUET 28
The Producer-Consumer Problem
The buffer is empty; the consumer is about to read
count = 0
Scheduler decides at that very instant to stop
consumer and start producer
The producer inserts an item and increases count by 1
The producer will wake the consumer up
The consumer was not logically sleeping. So, wake
signal is lost.
The consumer, on its next run, sees count = 0 and
sleeps
Rushdi Shams, Dept of CSE, KUET 29
The Producer-Consumer Problem
Soon, the producer fills up the buffer and also goes to sleep
Both will sleep forever
The main problem here is the lost wake up signal.
If it were not lost, everything would have worked
To solve this problem, we can use wake up waiting bit
When a wake up is sent to a process (producer or consumer)
that is not sleeping, this bit will be set.
When the sender goes to sleep, it checks this bit
If it is on, then the process will not sleep itself (because
someone MAYBE sleeping)
Rushdi Shams, Dept of CSE, KUET 30
Semaphores
It is simply a variable that holds the number of
wakeups saved for future use
It is 0 indicating that no wakeups are saved
It is a positive value indicating number of wakeups
saved
Rushdi Shams, Dept of CSE, KUET 31
Semaphores
There are 2 operations on semaphores-
Down- checks if value of semaphore is greater than 0.
if yes, it decrements the value and continues. If no,
then it is put to sleep.
Up- increments its value by 1. If there were sleeping
processes, any one of them randomly is awakened.
It is guaranteed that if one semaphore operation is
started, no other process can access it. They will have
their chance after operating process is completed/
blocked
Rushdi Shams, Dept of CSE, KUET 32
Producer-Consumer Problem
with Semaphores
Rushdi Shams, Dept of CSE, KUET 33
Rushdi Shams, Dept of CSE, KUET 34
Barriers
Some applications are divided into phases
And have the rule that no process may proceed to the
next phase until all processes are ready to proceed to
the next phase.
This behavior maybe achieved by placing a Barrier at
the end of each phase.
When a process reaches the barrier, it is blocked until
all processes reach the barrier.
Rushdi Shams, Dept of CSE, KUET 35
Barriers
Rushdi Shams, Dept of CSE, KUET 36
Classical IPC Problems
Rushdi Shams, Dept of CSE, KUET 37
Dining Philosopher Problem
Five Philosophers seated
around the circular table
Each has a plate of Spaghetti
Each needs two forks to eat it
Between each pair of plates
there is one fork
Rushdi Shams, Dept of CSE, KUET 38
Dining Philosopher Problem
The lives of the philosophers
consist of two things- eat and
think
When a philosopher is
hungry, she tries to acquire
her left/ right fork, one at a
time, in either order
She only eats after successful
acquisition of the forks
She eats for a while and then
puts them back to think
Rushdi Shams, Dept of CSE, KUET 39
Dining Philosopher Problem
Is it possible to have a
solution so that no
philosophers will be
annoyed? (when her turn is
eating, she eats; when her
turn is thinking, she thinks)
Rushdi Shams, Dept of CSE, KUET 40
Solutions
Philosopher will wait until its
desired fork is available
She will grab it when it’s
available
What if all the five
philosophers take their left
forks simultaneously?
None will be able to take
their right forks; there will be
deadlock
Rushdi Shams, Dept of CSE, KUET 41
Solutions
After taking the left fork,
philosopher will check if its
right fork is available
If it’s not, philosopher puts
back her left fork, wait for
some times and proceeds
again in similar way
What if all philosophers start
simultaneously?
They will never find their
right fork available causing
starvation
Rushdi Shams, Dept of CSE, KUET 42
Solutions
Using random start timer can
solve this problem, but not
ultimately
Ethernet LAN works in this
way, and this happens to be
finer solution, but again, not
the best; there is always a
chance to have a failure
Rushdi Shams, Dept of CSE, KUET 43
Solutions
Well, there is a solution that
will stop deadlock and
starvation
When philosopher wants to
acquire a fork, she downs
mutex; when she releases,
she ups mutex
The only drawback is only 1
of 5 philosophers can eat at a
time though there is a best
chance of 2 philosophers
eating at same time
Rushdi Shams, Dept of CSE, KUET 44
Solutions
Our last solution will be
deadlock free and achieve
maximum parallelism.
A philosopher will have 3
states- eating, thinking, or
hungry (trying to acquire
forks)
A philosopher will move to
eating state only if none of
the neighbors is eating
Only need is that each
philosopher will have
individual semaphores
Rushdi Shams, Dept of CSE, KUET 45
The Readers-Writers Problem
Dining philosopher problem defines the situation
where processes compete for limited resources
The Readers-Writers problem defines the situation
where database access is required.
A reader reads… the writer writes… but the reader is
away and with an old value from the database: simply,
this is the readers-writers problem
Rushdi Shams, Dept of CSE, KUET 46
Solutions
When a reader comes along, it UPs a semaphore-
means, hey, we are reading, do not disturb
If a writer comes, then it has to wait.
If more readers come, they are allowed
If reader comes along and along the writer just sits
duck.
Rushdi Shams, Dept of CSE, KUET 47
Solution
When an active reader is reading, then a writer
comes.
It sees that a reader is reading, the writer then waits
If more reader comes, they are queued
When the active reader finishes, the writer takes
place its schedule
After finishing of writer, the queued readers are given
chances.
Concurrency problem and lower performance is key
issue here
Rushdi Shams, Dept of CSE, KUET 48
The Sleeping Barber Problem
In a barber shop, there is one
barber, some chairs and some
customers
A barber sleeps if there is no
customer (not even on chairs,
waiting for a haircut )
A customer wakes up the barber
if it’s his turn to get his haircut
A customer waits if there is any
chair left
A customer leaves, if all the
chairs are occupied
Rushdi Shams, Dept of CSE, KUET 49
Solution
Rushdi Shams, Dept of CSE, KUET 50
Reference
Modern Operating Systems (2nd
Edition)
by Andrew S. Tanenbaum

More Related Content

What's hot

multiprocessors and multicomputers
 multiprocessors and multicomputers multiprocessors and multicomputers
multiprocessors and multicomputersPankaj Kumar Jain
 
Multivector and multiprocessor
Multivector and multiprocessorMultivector and multiprocessor
Multivector and multiprocessorKishan Panara
 
Distributed shred memory architecture
Distributed shred memory architectureDistributed shred memory architecture
Distributed shred memory architectureMaulik Togadiya
 
Real-Time Scheduling
Real-Time SchedulingReal-Time Scheduling
Real-Time Schedulingsathish sak
 
Pipelining and ILP (Instruction Level Parallelism)
Pipelining and ILP (Instruction Level Parallelism) Pipelining and ILP (Instruction Level Parallelism)
Pipelining and ILP (Instruction Level Parallelism) A B Shinde
 
Chapter 2 Time boxing & agile models
Chapter 2   Time boxing & agile modelsChapter 2   Time boxing & agile models
Chapter 2 Time boxing & agile modelsGolda Margret Sheeba J
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSKathirvel Ayyaswamy
 
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
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- IntroductionDebasis Das
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Ravindra Raju Kolahalam
 

What's hot (20)

multiprocessors and multicomputers
 multiprocessors and multicomputers multiprocessors and multicomputers
multiprocessors and multicomputers
 
Multivector and multiprocessor
Multivector and multiprocessorMultivector and multiprocessor
Multivector and multiprocessor
 
Reader Writer problem
Reader Writer problemReader Writer problem
Reader Writer problem
 
Semaphores
SemaphoresSemaphores
Semaphores
 
4.6 halting problem
4.6 halting problem4.6 halting problem
4.6 halting problem
 
Distributed shred memory architecture
Distributed shred memory architectureDistributed shred memory architecture
Distributed shred memory architecture
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
Real-Time Scheduling
Real-Time SchedulingReal-Time Scheduling
Real-Time Scheduling
 
Pipelining and ILP (Instruction Level Parallelism)
Pipelining and ILP (Instruction Level Parallelism) Pipelining and ILP (Instruction Level Parallelism)
Pipelining and ILP (Instruction Level Parallelism)
 
Generation of os
Generation of osGeneration of os
Generation of os
 
Chapter 2 Time boxing & agile models
Chapter 2   Time boxing & agile modelsChapter 2   Time boxing & agile models
Chapter 2 Time boxing & agile models
 
Mutual exclusion
Mutual exclusionMutual exclusion
Mutual exclusion
 
Parallel Algorithms
Parallel AlgorithmsParallel Algorithms
Parallel Algorithms
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"Operating Systems - "Chapter 5 Process Synchronization"
Operating Systems - "Chapter 5 Process Synchronization"
 
Mainframe
MainframeMainframe
Mainframe
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Advanced Operating System- Introduction
Advanced Operating System- IntroductionAdvanced Operating System- Introduction
Advanced Operating System- Introduction
 
Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]Inter Process Communication Presentation[1]
Inter Process Communication Presentation[1]
 

Similar to Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems

Lecture 11,12 and 13 deadlocks
Lecture 11,12 and 13  deadlocksLecture 11,12 and 13  deadlocks
Lecture 11,12 and 13 deadlocksRushdi Shams
 
Lecture 1 and 2 processes
Lecture 1 and 2  processesLecture 1 and 2  processes
Lecture 1 and 2 processesRushdi Shams
 
Interprocess Communication
Interprocess CommunicationInterprocess Communication
Interprocess CommunicationDilum Bandara
 
Lecture 3 and 4 threads
Lecture 3 and 4  threadsLecture 3 and 4  threads
Lecture 3 and 4 threadsRushdi Shams
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.pptjayverma27
 
L11 l12 l13 transaction management
L11 l12 l13  transaction managementL11 l12 l13  transaction management
L11 l12 l13 transaction managementRushdi Shams
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksMukesh Chinta
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfAmanuelmergia
 
Ch17 OS
Ch17 OSCh17 OS
Ch17 OSC.U
 
Advanced os 5th unit
Advanced os 5th unitAdvanced os 5th unit
Advanced os 5th unitMujtaba Ahmed
 
Operating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docxOperating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docxminaltmv
 
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncationLM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncationMani Deepak Choudhry
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlockstech2click
 

Similar to Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems (20)

Lecture 11,12 and 13 deadlocks
Lecture 11,12 and 13  deadlocksLecture 11,12 and 13  deadlocks
Lecture 11,12 and 13 deadlocks
 
Lecture 1 and 2 processes
Lecture 1 and 2  processesLecture 1 and 2  processes
Lecture 1 and 2 processes
 
Interprocess Communication
Interprocess CommunicationInterprocess Communication
Interprocess Communication
 
Lecture 3 and 4 threads
Lecture 3 and 4  threadsLecture 3 and 4  threads
Lecture 3 and 4 threads
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
 
Process coordination
Process coordinationProcess coordination
Process coordination
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating system
 
L11 l12 l13 transaction management
L11 l12 l13  transaction managementL11 l12 l13  transaction management
L11 l12 l13 transaction management
 
Operating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and DeadlocksOperating Systems - Process Synchronization and Deadlocks
Operating Systems - Process Synchronization and Deadlocks
 
Lecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdfLecture 5- Process Synchonization_revised.pdf
Lecture 5- Process Synchonization_revised.pdf
 
Deadlock
DeadlockDeadlock
Deadlock
 
Ch17 OS
Ch17 OSCh17 OS
Ch17 OS
 
OSCh17
OSCh17OSCh17
OSCh17
 
OS_Ch17
OS_Ch17OS_Ch17
OS_Ch17
 
Advanced os 5th unit
Advanced os 5th unitAdvanced os 5th unit
Advanced os 5th unit
 
Cs 704 d set3
Cs 704 d set3Cs 704 d set3
Cs 704 d set3
 
Operating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docxOperating System- INTERPROCESS COMMUNICATION.docx
Operating System- INTERPROCESS COMMUNICATION.docx
 
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncationLM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
LM9 - OPERATIONS, SCHEDULING, Inter process xommuncation
 
Operating system Deadlock
Operating system DeadlockOperating system Deadlock
Operating system Deadlock
 
Process Synchronization And Deadlocks
Process Synchronization And DeadlocksProcess Synchronization And Deadlocks
Process Synchronization And Deadlocks
 

More from Rushdi Shams

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchRushdi Shams
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IRRushdi Shams
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101Rushdi Shams
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processingRushdi Shams
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: ParsingRushdi Shams
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translationRushdi Shams
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translationRushdi Shams
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semanticsRushdi Shams
 
Propositional logic
Propositional logicPropositional logic
Propositional logicRushdi Shams
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logicRushdi Shams
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structureRushdi Shams
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representationRushdi Shams
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hackingRushdi Shams
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)Rushdi Shams
 

More from Rushdi Shams (20)

Research Methodology and Tips on Better Research
Research Methodology and Tips on Better ResearchResearch Methodology and Tips on Better Research
Research Methodology and Tips on Better Research
 
Common evaluation measures in NLP and IR
Common evaluation measures in NLP and IRCommon evaluation measures in NLP and IR
Common evaluation measures in NLP and IR
 
Machine learning with nlp 101
Machine learning with nlp 101Machine learning with nlp 101
Machine learning with nlp 101
 
Semi-supervised classification for natural language processing
Semi-supervised classification for natural language processingSemi-supervised classification for natural language processing
Semi-supervised classification for natural language processing
 
Natural Language Processing: Parsing
Natural Language Processing: ParsingNatural Language Processing: Parsing
Natural Language Processing: Parsing
 
Types of machine translation
Types of machine translationTypes of machine translation
Types of machine translation
 
L1 l2 l3 introduction to machine translation
L1 l2 l3  introduction to machine translationL1 l2 l3  introduction to machine translation
L1 l2 l3 introduction to machine translation
 
Syntax and semantics
Syntax and semanticsSyntax and semantics
Syntax and semantics
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
 
Probabilistic logic
Probabilistic logicProbabilistic logic
Probabilistic logic
 
L15 fuzzy logic
L15  fuzzy logicL15  fuzzy logic
L15 fuzzy logic
 
Knowledge structure
Knowledge structureKnowledge structure
Knowledge structure
 
Knowledge representation
Knowledge representationKnowledge representation
Knowledge representation
 
First order logic
First order logicFirst order logic
First order logic
 
Belief function
Belief functionBelief function
Belief function
 
L5 understanding hacking
L5  understanding hackingL5  understanding hacking
L5 understanding hacking
 
L4 vpn
L4  vpnL4  vpn
L4 vpn
 
L3 defense
L3  defenseL3  defense
L3 defense
 
L2 Intrusion Detection System (IDS)
L2  Intrusion Detection System (IDS)L2  Intrusion Detection System (IDS)
L2 Intrusion Detection System (IDS)
 
L1 phishing
L1  phishingL1  phishing
L1 phishing
 

Recently uploaded

USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 

Recently uploaded (20)

USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 

Lecture 7, 8, 9 and 10 Inter Process Communication (IPC) in Operating Systems

  • 1. Rushdi Shams, Dept of CSE, KUET 1 Operating SystemsOperating Systems Inter-processInter-process CommunicationCommunication Version 1.0
  • 2. Rushdi Shams, Dept of CSE, KUET 2 IPC One process, sometimes, require the output of other process Therefore, there is a need of well structured communication among processes. Not preferring interrupts to draw attention.
  • 3. Rushdi Shams, Dept of CSE, KUET 3 IPC  Three issues in IPC- 1. How one process can pass information to another 2. Making sure that two or more processes do not get into each other’s way when engaging in critical activities (both wants last 1 MB space of virtual memory) 3. Proper sequencing when dependency is present (if A produces data that B prints, then B cannot print unless A is producing some data)
  • 4. Rushdi Shams, Dept of CSE, KUET 4 Inter-thread Communication  In case of ITC, the same issues are concerns.  The first one is not a headache as threads share some common resources and address space; so, they can easily communicate  But the other twos are issues in ITC as well.
  • 5. Rushdi Shams, Dept of CSE, KUET 5 Race Condition A process wants to print a file. It enters the file name in a special printer directory The Printer Daemon periodically checks to see if there is any file to print If any file is there the Printer Daemon prints them and removes their names from the directory
  • 6. Rushdi Shams, Dept of CSE, KUET 6 Race Condition Imagine our directory has a very large number of slots (numbered 0,1,2,…) and each one can hold a file name There are two shared variables- out that points to the next file to be printed and in that points to the next free slot in the directory
  • 7. Rushdi Shams, Dept of CSE, KUET 7 Race Condition
  • 8. Rushdi Shams, Dept of CSE, KUET 8 Race Condition A reads in and stores the values 7 to its local variable Then a context switch from A to B occurs B also reads in and stores the value 7 to its local variable B continues to run and it stores the name of its file in slot 7 and updates in to 8. Then it goes off and does other things
  • 9. Rushdi Shams, Dept of CSE, KUET 9 Race Condition A runs again starting from the place it left off It looks its local variable and finds 7 there and writes the file name in slot 7 Then A sets in to 8 As everything went fine, the printer daemon will not raise any error
  • 10. Rushdi Shams, Dept of CSE, KUET 10 Race Condition Process B never gets the chance Situations like this where two or more processes are reading or writing some shared data and the final result depends on who ran precisely are called race conditions
  • 11. Rushdi Shams, Dept of CSE, KUET 11 Critical Regions How can we avoid race conditions? One way to avoid that is prohibiting more than one process from reading and writing the shared data at the same time This is called Mutual Exclusion
  • 12. Rushdi Shams, Dept of CSE, KUET 12 Critical Regions On the other hand, let’s think in abstract way. A process is busy doing internal computations and other things that do not lead race conditions And sometimes it is busy to access shared memory and files or in doing other critical things that lead race conditions The part of the program where shared memory or resources are accesses is called Critical Regions
  • 13. Rushdi Shams, Dept of CSE, KUET 13 Critical Regions  We need four conditions to hold for a good solution with mutual exclusion- 1. No two processes simultaneously in critical region 2. No assumptions made about speeds or numbers of CPUs 3. No process running outside its critical region may block another process 4. No process must wait forever to enter its critical region
  • 14. Rushdi Shams, Dept of CSE, KUET 14 Mutual Exclusion with Critical Regions
  • 15. Rushdi Shams, Dept of CSE, KUET 15 How can we achieve mutual exclusion? Now, let’s examine various proposals to achieve mutual exclusion While one process is busy to update shared memory in its critical region, no other process will enter its critical region and cause trouble
  • 16. Rushdi Shams, Dept of CSE, KUET 16 Disabling Interrupts When a process enters into its critical region, it disables all interrupts While leaving its critical region, it re-enables all interrupts Unattractive and unwise to give user processes the power of turning off interrupts. What if one of them did it and never turned them on again!!  That is the end of the system!!!  It is often useful technique within the OS itself but not suitable as a general mutual exclusion mechanism
  • 17. Rushdi Shams, Dept of CSE, KUET 17 Lock Variables It’s a software solution When a process wants to enter into the critical region, it checks the lock variable If it is 0, the process sets it to 1 and enters into its critical region If it is 1, the process waits
  • 18. Rushdi Shams, Dept of CSE, KUET 18 Lock Variables One process reads the lock and sees 0 Before it sets 1, another process is scheduled, runs and sets the lock 1 When the first process runs, it will also set the lock 1 Two processes will be in their critical regions in the same time.
  • 19. Rushdi Shams, Dept of CSE, KUET 19 Strict Alternation turn is a variable initially 0 keeps track of whose turn it is to enter critical regions Process 0 inspects turn and finds 0 and enters into its critical region Process 1 finds turn to be 0 and continuously tests the value of turn Continuously testing a variable until some value appears is called Busy Waiting
  • 20. Rushdi Shams, Dept of CSE, KUET 20 Strict Alternation It should usually be avoided as it wastes CPU time Can be useful when short busy waiting is probable Requires strict alternating process to provide better result Inefficient when one process is much slower than the other
  • 21. Rushdi Shams, Dept of CSE, KUET 21 Peterson’s Solution
  • 22. Rushdi Shams, Dept of CSE, KUET 22  So far, the techniques we learnt (except disabling interrupts)- 1. Lock variables 2. Strict Alternation 3. Peterson’s Solution To achieve mutual exclusion, all have a common problem- Busy Waiting  In case of prioritized scheduling, low prioritized processes will never be fed if Busy Waiting takes place
  • 23. Rushdi Shams, Dept of CSE, KUET 23 Different Mechanisms with Sleep and Wake Now, we will see more mechanisms to achieve mutual exclusion These techniques will use Sleep and Wake- two system calls Sleep causes a process to be suspended until another process wakes it up Wake causes a process to wake up
  • 24. Rushdi Shams, Dept of CSE, KUET 24 The Producer-Consumer Problem When the producer sees a full buffer and goes to sleep. When the consumer takes out an item, it awakes the producer When the consumer sees an empty buffer and goes to sleep. When the producer puts an item, it awakes the consumer
  • 25. Rushdi Shams, Dept of CSE, KUET 25 The Producer-Consumer Problem We will use count as a variable to stop race conditions If the maximum no of information the buffer stores in N, then producer first checks if count = N. If yes, then it sleeps; otherwise it will add an item and increment count by 1 The consumer tests count. If count = 0, then it sleeps; otherwise it removes an information and decrements count by 1
  • 26. Rushdi Shams, Dept of CSE, KUET 26 The Producer-Consumer Problem
  • 27. Rushdi Shams, Dept of CSE, KUET 27 The Producer-Consumer Problem  Two processes share a common, fixed-sized buffer  The producer puts information into the buffer  The consumer takes it out  Problem arises when- 1. Producer wants to put information into a buffer that is full 2. Consumer wants to get information from a buffer that is empty
  • 28. Rushdi Shams, Dept of CSE, KUET 28 The Producer-Consumer Problem The buffer is empty; the consumer is about to read count = 0 Scheduler decides at that very instant to stop consumer and start producer The producer inserts an item and increases count by 1 The producer will wake the consumer up The consumer was not logically sleeping. So, wake signal is lost. The consumer, on its next run, sees count = 0 and sleeps
  • 29. Rushdi Shams, Dept of CSE, KUET 29 The Producer-Consumer Problem Soon, the producer fills up the buffer and also goes to sleep Both will sleep forever The main problem here is the lost wake up signal. If it were not lost, everything would have worked To solve this problem, we can use wake up waiting bit When a wake up is sent to a process (producer or consumer) that is not sleeping, this bit will be set. When the sender goes to sleep, it checks this bit If it is on, then the process will not sleep itself (because someone MAYBE sleeping)
  • 30. Rushdi Shams, Dept of CSE, KUET 30 Semaphores It is simply a variable that holds the number of wakeups saved for future use It is 0 indicating that no wakeups are saved It is a positive value indicating number of wakeups saved
  • 31. Rushdi Shams, Dept of CSE, KUET 31 Semaphores There are 2 operations on semaphores- Down- checks if value of semaphore is greater than 0. if yes, it decrements the value and continues. If no, then it is put to sleep. Up- increments its value by 1. If there were sleeping processes, any one of them randomly is awakened. It is guaranteed that if one semaphore operation is started, no other process can access it. They will have their chance after operating process is completed/ blocked
  • 32. Rushdi Shams, Dept of CSE, KUET 32 Producer-Consumer Problem with Semaphores
  • 33. Rushdi Shams, Dept of CSE, KUET 33
  • 34. Rushdi Shams, Dept of CSE, KUET 34 Barriers Some applications are divided into phases And have the rule that no process may proceed to the next phase until all processes are ready to proceed to the next phase. This behavior maybe achieved by placing a Barrier at the end of each phase. When a process reaches the barrier, it is blocked until all processes reach the barrier.
  • 35. Rushdi Shams, Dept of CSE, KUET 35 Barriers
  • 36. Rushdi Shams, Dept of CSE, KUET 36 Classical IPC Problems
  • 37. Rushdi Shams, Dept of CSE, KUET 37 Dining Philosopher Problem Five Philosophers seated around the circular table Each has a plate of Spaghetti Each needs two forks to eat it Between each pair of plates there is one fork
  • 38. Rushdi Shams, Dept of CSE, KUET 38 Dining Philosopher Problem The lives of the philosophers consist of two things- eat and think When a philosopher is hungry, she tries to acquire her left/ right fork, one at a time, in either order She only eats after successful acquisition of the forks She eats for a while and then puts them back to think
  • 39. Rushdi Shams, Dept of CSE, KUET 39 Dining Philosopher Problem Is it possible to have a solution so that no philosophers will be annoyed? (when her turn is eating, she eats; when her turn is thinking, she thinks)
  • 40. Rushdi Shams, Dept of CSE, KUET 40 Solutions Philosopher will wait until its desired fork is available She will grab it when it’s available What if all the five philosophers take their left forks simultaneously? None will be able to take their right forks; there will be deadlock
  • 41. Rushdi Shams, Dept of CSE, KUET 41 Solutions After taking the left fork, philosopher will check if its right fork is available If it’s not, philosopher puts back her left fork, wait for some times and proceeds again in similar way What if all philosophers start simultaneously? They will never find their right fork available causing starvation
  • 42. Rushdi Shams, Dept of CSE, KUET 42 Solutions Using random start timer can solve this problem, but not ultimately Ethernet LAN works in this way, and this happens to be finer solution, but again, not the best; there is always a chance to have a failure
  • 43. Rushdi Shams, Dept of CSE, KUET 43 Solutions Well, there is a solution that will stop deadlock and starvation When philosopher wants to acquire a fork, she downs mutex; when she releases, she ups mutex The only drawback is only 1 of 5 philosophers can eat at a time though there is a best chance of 2 philosophers eating at same time
  • 44. Rushdi Shams, Dept of CSE, KUET 44 Solutions Our last solution will be deadlock free and achieve maximum parallelism. A philosopher will have 3 states- eating, thinking, or hungry (trying to acquire forks) A philosopher will move to eating state only if none of the neighbors is eating Only need is that each philosopher will have individual semaphores
  • 45. Rushdi Shams, Dept of CSE, KUET 45 The Readers-Writers Problem Dining philosopher problem defines the situation where processes compete for limited resources The Readers-Writers problem defines the situation where database access is required. A reader reads… the writer writes… but the reader is away and with an old value from the database: simply, this is the readers-writers problem
  • 46. Rushdi Shams, Dept of CSE, KUET 46 Solutions When a reader comes along, it UPs a semaphore- means, hey, we are reading, do not disturb If a writer comes, then it has to wait. If more readers come, they are allowed If reader comes along and along the writer just sits duck.
  • 47. Rushdi Shams, Dept of CSE, KUET 47 Solution When an active reader is reading, then a writer comes. It sees that a reader is reading, the writer then waits If more reader comes, they are queued When the active reader finishes, the writer takes place its schedule After finishing of writer, the queued readers are given chances. Concurrency problem and lower performance is key issue here
  • 48. Rushdi Shams, Dept of CSE, KUET 48 The Sleeping Barber Problem In a barber shop, there is one barber, some chairs and some customers A barber sleeps if there is no customer (not even on chairs, waiting for a haircut ) A customer wakes up the barber if it’s his turn to get his haircut A customer waits if there is any chair left A customer leaves, if all the chairs are occupied
  • 49. Rushdi Shams, Dept of CSE, KUET 49 Solution
  • 50. Rushdi Shams, Dept of CSE, KUET 50 Reference Modern Operating Systems (2nd Edition) by Andrew S. Tanenbaum