Concurrency: Mutual Exclusion and Synchronization: Operating Systems: Internals and Design Principles
Concurrency: Mutual Exclusion and Synchronization: Operating Systems: Internals and Design Principles
Concurrency: Mutual Exclusion and Synchronization: Operating Systems: Internals and Design Principles
Systems: Chapter 5
Internals Concurrency: Mutual
and Design
Principles Exclusion and
Synchronization
Seventh Edition
By William Stallings
Operating Systems:
Internals and Design Principles
Te r
ms
Solu
tion
Figure 5.9 An Incorrect Solution to the Infinite-Buffer Producer/Consumer Problem Using Binary Semaphores
Pos
sibl
e
Sol
utio
n
Corr
ect
Solu
tion
Figure 5.10 A Correct Solution to the Infinite-Buffer Producer/Consumer Problem Using Binary Semaphores
Se
Sol
m
uti
ap
on
ho
Usi
res
ng
Finite
Circular
Buffer
Solutio
n
Using
Sema
phore
s
Figure 5.13 A Solution to the Bounded-Buffer Producer/Consumer Problem Using Semaphores
Implementation of
Semaphores
Imperativethat the semWait and semSignal
operations be implemented as atomic primitives
Can be implemented in hardware or firmware
Softwareschemes such as Dekker’s or
Peterson’s algorithms can be used
Useone of the hardware-supported schemes
for mutual exclusion
Monitors
Programming language construct that provides
equivalent functionality to that of semaphores and is
easier to control
Implemented in a number of programming languages
including Concurrent Pascal, Pascal-Plus, Modula-2,
Modula-3, and Java
Has also been implemented as a program library
Software module consisting of one or more
procedures, an initialization sequence, and local data
Monitor Characteristics
Synchronization
Achieved by the use of condition variables that are
contained within the monitor and accessible only
within the monitor
Condition variables are operated on by two functions:
cwait(c): suspend execution of the calling process on
condition c
csignal(c): resume execution of some process blocked
after a cwait on the same condition
Structure of a Monitor
Table 5.5 Design Characteristics of Message Systems for Interprocess Communication and Synchronization
Synchronization
Blocking Send,
Blocking Receive
Both
sender and receiver are blocked until the
message is delivered
Sometimes referred to as a rendezvous
Allowsfor tight synchronization between
processes
Nonblocking Send
Addressing
Schemes for specifying processes in send
and receive primitives fall into two
categories:
Direct Addressing
Send primitive includes a specific identifier of
the destination process
Receive primitive can be handled in one of two
ways:
require that the process explicitly designate
a sending process
effective for cooperating concurrent processes
implicit addressing
source parameter of the receive primitive possesses a value
returned when the receive operation has been performed
Indirect Addressing
Indirect Process
C
o
m
m
un
ica
tio
n
General Message Format
Mutual Exclusion
Message Passing Example
So
lut
io
n
Figure 5.22 A Solution to the Readers/Writers Problem Using Semaphore: Readers Have Priority
Solution:
Writers Have Priority
Figure 5.23 A Solution to the Readers/Writers Problem Using Semaphore: Writers Have Priority
State of the Process Queues
Message Passing