CSE 7343/5343, Spring 2003
Topic 4: Process Synchronization/Coordination
Prof. Jeff Tian, CSE/SoE/SMU, Dallas, TX 75275
tian@engr.smu.edu; www.engr.smu.edu/~tian/class/7343.03s
- Dates: 2/6-11/03:
- Reading: Ch 7.
General problem
- independent vs. cooperating processes
- earlier examples: reader/writer, consumer/producer (bounded buffer), etc.
- general assumption: shared resources
typically memory/data variables
- potential problems among concurrent processes
- consumer/producer example in book
- item count update by both consumer and producer
- multiprogramming: interleaving condition
- truly parallel: parallel access
- race condition: execution results dependent on exact order
- general situation: (data) dependency analysis
- read/write (or define/use)
- relations: DD, DU, UD, UU
- followup analysis in testing course (CSE 7314)
- critical-section: a general/important problem
- other problems: process cooperation/IPC/synchronization
Critical-section problem
- critical section (CS): limited access
- narrow sense: at most 1 access
also called mutual exclusion problem
- solution requirement:
- mutual exclusion
- progress
- bounded waiting (no starvation)
- general setup: repeat { S1; CR; S2 }
- solution: entry and exit conditions
- solution strategy: software vs. hardware
CS problem: Software solutions
- two process software solution
then general solution
- algorithm 1: (Fig 7.2, p.193)
- use of turn
- entry: check turn
- exit: set turn to other
- problem: progress when not turn
- algorithm 2: (Fig 7.3, p.194)
- flags
- entry: set own flag and see other flag
- exit: reset own flag
- problem: progress when both raise flags
(similar to deadlock problem)
- change entry order: mutex, both enter
- algorithm 3: (Fig 7.4, p.195)
- both turn and flag
- entry: raise flag, give other turn,
yield if other raised flag and have turn
- exit: reset flag
- why does it work?
- flag: signal
- turn: progress when contention occurs
- multiprocess solution:
bakery algorithm, Fig. 7.5, p.197
- difficulty of software solutions
CS problem: Hardware solutions
- single CPU: disabling interrupt
- atomic operations: test-and-set or swap
- "test-and-set" solution:
- definition: Fig 7.6, p.198
- solution: Fig 7.7, p.198
- global exclusive "lock" or "token"
- whoever performed it (atomically) first, will set & proceed
- whoever performed it later, will wait
- un-set (lock = false) initially
- un-set when done
- "swap" solution:
- definition: Fig 7.8, p.199
- solution: Fig 7.9, p.199
- similar to above
- global "lock"
- local "key"
- problem of bounded waiting?
- general solution Fig 7.10, p.200
read and understand yourself
CS/other problems: Generalized solutions with semaphores and monitors
- semaphore: generalized concept/tool
- concept: integer variable
- access only through P and V
P = wait, might cause blocking
V = signal, increment
classical definition p.201
- P, V, indivisible (atomic) operations
on value change
between "while" and "S--" in P.
- use in critical section problems
P(S) CS V(S), with S initialized to 1
critical section problem for any number of processes
- implementation:
blocking (p.203) instead of
busy waiting (p.201) or use spinlock
- solution to general IPC/cooperating process problem
- limited access instead of exclusive access section
- multiple semaphores:
possibility for deadlock
- binary vs general semaphores
Other classical coordination problem
- problems
- consumer-producer or bounded buffer
- reader-writer
- dining philosopher
- solution use semaphores
- general ideas (class), and then code (textbook)
- also, time for review
- consumer-producer or bounded buffer
- buffer size
- problems with update
- waiting conditions:
- full: producer
- empty: consumer
- both: update item count
- use of three semaphores
- solution: Fig 7.12 & 7.13, p.207
- reader-writer
- asymmetric processes: two types
- reader: multiple access possible
- writer: exclusive access
- waiting/blocking conditions :
- writer writing => everyone waiting
- reader reading => writer waiting
- key solution idea:
- reader as a "block" or "group"
first to enter or last one to leave need to act for the whole group
- writer as individuals
- solution for
writer (Fig 7.14, p.208)
reader (Fig 7.15, p.209)
- dining philosopher
- problem description
- key difference: distributed vs. centralized environment as before
- limited resource sharing
- communication through message passing
- solution
- deadlock possibility
- starvation possibility
- central knowledge implications
Review for exam#1
- question types:
- mostly similar to homework questions
- multiple choice also
- some homework problems
- key material:
- processes and threads; ideas & concepts
- scheduling: ideas and algorithms;
- synchronization/coordination:
concepts and CR/classical problem solutions
- general ideas about chapters 1-3
- 3 or 4 question sets (3-4 pages long)
Material to cover after exam#1
- monitors
- concept: generalized semaphores
- .wait and .signal on different conditions
critical regions (or conditional cr) problem
- use in general IPC problems
Prepared by Jeff Tian
(tian@engr.smu.edu).
Last update Feb. 12, 2003.