Lecture Notes for Operating Systems
Concurrency, 4 October 2000
- concurrency - more than one processes executing at the same time
- independently executing processes aren't the problem - shared resources
- sharing the cpu isn't the problem - uncoordinated sharing
- the concurrency problem - uncoordinated resource sharing among
concurrent processes
- three representative concurrency problems.
- the dining philosophers problem.
- example problem
- write a program that reads a tape drive, computes a while, and
writes another tape - the computation cannot start until the program has
both tape drives
- five identical copies of the program are to be run on a system
with five identical tape drives
- commands - get_tape(), compute(), release_tape()
- what does the program look like?
- model - due to dijkstra
- five philosophers, a table, plates of spaghetti, forks
- philosophers either think or eat, hungry; eating requires two
adjacent forks;
- some hungry philosopher eventually gets to eat
- every hungry philosopher eventually gets to eat
- a hungry philosopher that's eaten n meals has priority over a
hungry philosopher that's eaten m meals when n < m
- the readers-writers problem
- a never-ending stream of readers and writers access a database
- only one writer may change the database at a time, and only the
writer may access the database while its being changed
- any number of readers may access the database at the same time
- write an access program for readers and writers
- safe - good data gets written, good data gets read
- high throughput - better than sequential access
- timely information - writers aren't starved out
- the sleeping barber problem
- example problem
- a server provides the only access to a device - the disk server
- the disk server sleeps if there are no clients
- clients arrive and wake the server if necessary
- when there are no more clients, the server sleeps again.
- the scheduler's the problem here - it may swap executing processes
at any time
- the problem model
- a barber shop with one barber chair and an n-customer bench.
- when the shop is empty the barber is sleeping in the barber chair
- a customer enters the store
- empty - wake up the barber
- bench not full - take a seat
- bench full - blow off the hair cut
- how many new customers in the shop at once
- ipc - inter-process communication or coordination
- competing access to shared resources
- coordinated execution behavior - synchronization
- race conditions - unmediated access to shared resources; two threads
updating a common counter, interrupts
- idea - make shared access non-interruptible or atomic or serial
- follow on problem - decreased performance
- two-part solution
- mutual exclusion to prohibit shared access
- critical regions or sections to delimit the scope of mutual
exclusion
- rules
- mutual exclusion only in critical regions
- cpu abstracted away - number and speed
- processes outside cr may not block entry into the cr
- processes attempting to enter the cr eventually will
This page last modified on 4 October 2000.