Lecture Notes for Operating Systems
Concurrency Control Mechanisms, 9 October 2000
- mediate concurrent access to shared resources
- general solution: critical regions for mutually exclusive access to
shared resources
- general approach:
do something, enter critical region;
do
something;
do something, exit critical region
- do what on entry and exit?
- interrupt play
- on entry, increase priority or disable interrupts
- on exit, restore priority or interrupts
- good - cheap, certain, supported, short critical regions
- bad - privileged, easily abused, doesn't fail gracefully,
doesn't scale to multiprocessors, long critical regions
- simple software lock variables, flags, booleans...
- on entry: check flag, wait until true, set false
- on exit: set true
- good - cheap, quick
- bad - it doesn't work; flag a shared variable
- token passing
- on entry - wait until you get the token, then go
- on exit - pass the token on
- good - cheap, obviously correct
- bad - inefficient, unreliable
- correctly implemented software lock variables, flags, booleans;
dekker's, peterson's algorithms
- on entry - indicate intention, set flag, wait
- on exit - clear intention
- good - simple, fast
- bad - not so simple
- hardware supported lock variables, flags, booleans
- atomic read-modify-write instructions
- test and set - tst reg, addr: copy addr to reg, set addr to 1
- on entry - test and set until reg is 0
- on exit - set addr to 0
- good - cheap, simple, fast, correct
- bad - non-portable, test and set can be funky on multiprocessor
architectures, and some uniprocessors such as the alpha
- semaphores - a binary variable
- on entry - down(s): wait until s is 1, then subtract 1 and go
- on exit - up(s): if s is 0 add 1
- good - simple, intuitive, efficient
- bad - unstructured, low-level, non-portable
- many semaphore types: binary, split binary, counting
- monitors - data abstraction and structuring
- encapsulates data, provides access via entries
- waiting, condition variables
- on entry - call a monitor entry procedure
- on exit - return from the monitor entry procedure
- good - structured, understandable
- bad - subtle (nested monitors), heavyweight
- message passing - (almost) nothing shared
- send and receive
- identifying sender and receiver
- synchornous or asyncnronous - rendezvous in ada
- higher level mechanisms - remote procedure call (rpc)
- suspending - block or busy-wait
This page last modified on 10 October 2000.