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
Ninth Edition
By William Stallings
Multiple
Applications
Structured
Applications Operating
Invented to allow System
processing time to Structure
be shared among Extension of
active applications modular design
and structured
programming OS themselves
implemented as a
set of processes
or threads
Some Key
Terms Related
to
Concurrency
Dijkstra reported an algorithm for mutual exclusion for two processes, designed by
the Dutch mathematician Dekker
Following Dijkstra, we develop the solution in stages
This approach has the advantage if illustrating many of the common bugs encountered in
developing concurrent programs
Protect the data and physical resources of each process against unintended interference by
other processes
The functioning of a process, and the output it produces, must be independent of the speed at
And which its execution is carried out relative to the speed of other concurrent processes
Primitives for sending and receiving messages may be provided as part of the
programming language or provided by the OS kernel
There is no way to
You don’t know
There is no way to know which process
whether another
know before a process will continue
process is waiting so
decrements a immediately on a
the number of
semaphore whether it uniprocessor system
unblocked processes
will block or not when two processes are
may be zero or one
running concurrently
Strong Semaphores
• The process that has been blocked the longest is
released from the queue first (FIFO)
Weak Semaphores
• The order in which processes are removed from the
queue is not specified
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Producer/Consumer Problem
Synchronization Communication
• To enforce mutual • To exchange
exclusion information
Table 5.5
Design Characteristics of Message Systems for
Interprocess Communication and Synchronization
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Synchronization
When a r
executed eceive primitive
in a proc is
es s th e
a message two possi re are
Communication of sses bilities:
between two proce n If there
atio
implies synchroniz i
process s no waiting me
between the two i s
arrives s blocked until sage the
o a
execute, r the process co message
abandon n
ing the a tinues to
receive ttempt t
not o
The receiver can ntil
ge u
receive a messa by If a mess
ag
it has been sent been sen e has previously
t
another process received the message is
and exe
continue cution
s
Direct Indirect
addressing addressing
Both readers and writers with read first •wsem set by reader
•rsem set by writer
•all writers queue on wsem
•one reader queues on rsem
•other readers queue on z
Both readers and writers with write first •wsem set by writer
•rsem set by writer
•writers queue on wsem
•one reader queues on rsem
•other readers queue on z
Table 5.6
State of the Process Queues for Program of Figure 5.26
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
© 2017 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Summary
Mutual exclusion: software approaches
Dekker’s algorithm
Monitors
Peterson’s algorithm Monitor with signal
Alternate model of monitors with notify
Principles of concurrency
and broadcast
Race condition
OS concerns Message passing
Process interaction Synchronization
Requirements for mutual exclusion
Addressing
Mutual exclusion: hardware support Message format
Interrupt disabling Queueing discipline
Special machine instructions
Mutual exclusion
Semaphores
Mutual exclusion
Readers/writers problem
Producer/consumer problem
Readers have priority
Implementation of semaphores Writers have priority