Lecture 1
Review -- on board at start
Pattern Mechanism Examples
wait inside while wait/signal semaphores, BB, RW
priority to delayed double if stmts FIFO sem, SJN
processes
(passing the cond.)
scheduling priority wait SJN, timer 2
covering condition signal_all timer 1
rendezvous wait loop & signal barber, disk (today)
on both sides
today: program structures, Java, Pthreads, SR
Disk Scheduling Problem -- Section 5.3
idea of problem; details in text and in undergrad OS class
(a) separate scheduler
diagram of structure as shown in Figure 5.12
simple structure, but the scheduler is not encapsulated or protected
(b) scheduler as an intermediary
diagram of structure as shown in Figure 5.14
disk is a process
simpler user interface than (a) [only one call]
can call use and get in any order; need a rendezvous
scheduler is a sleeping barber, but more complex
(c) nested monitor calls
diagram of structure as shown in Figure 5.17
one less process and simpler, transparent scheduler
requires OPEN calls that release the lock in the caller
as opposed to CLOSED calls that retain the lock
[I did not present code for these but referred students to the text;
they'll need to look to do their homework!]
Java -- Section 5.4
classes (patterns) and objects (instances)
threads
synchronized methods and code blocks -- << S; >>
one lock per synchronized object and one implicit delay queue
operations are wait(), notify() and notifyAll()
signal and continue semantics for notify()
no condition variable declarations or arrays of conditions
no priority wait
example: readers/writers in Java
transparency for rw.real.java
started with slide 2, which shows the threads
then covered slide 1 -- notice interface and nested calls
Pthreads -- Section 5.5
mutex -- basic lock
condition variables -- queue and associated lock
wait(&cond, &mutex)
signal(&cond)
broadcast(&cond)
signal and continue semantics
example: summing the elements of a matrix; uses a thread for each strip
transparency for matrix.sum.c
(this is the same as the program in Figure 5.18)
declarations of threads and condition variables
initialization
calls of Barrier()
barrier monitor -- uses a simple counter barrier
Simulating Monitors in SR -- see SR book and Section 8.7
resources -- we have seen
globals -- shared declarations, procedures, ...
use semaphores, either directly or to simulate monitor components
(as shown in Figure 6.7)
example: readers/writers simulation
transparency for rw.simulation.sr
slide two -- main resource
processes, loops
nap() to simulate delays; random() to make them variable length
slide one -- Database global
import it
interface (spec) -- read() and write()
body -- notice use of sems and local calls