Week 3 Flashcards
cmpxchg
Test and set for Intel. Source must be a register and destination is usually a address. Can’t be the A register. Put destination address into eax register. Compare it with dst register. If you get the correct address back, set zero flag to one and destination value to the source value. If not, set zero flag to zero and reset eax with dst register value.
ARM
RISC style instruction set. exchange process. If two processes get the value 0, the store lets the process know its not the first one to get a zero. It will loop back and try again.
Semaphores for synchronization
Set semaphore number higher.
Bounded buffer with semaphores
Have a full = 0, empty = 0, and mutex = 1 semaphore. Full represents slots with data, empty represents buffer without data.
Producer semaphore
Wait(empty), wait(mutex), Add to buffer, signal(mutex), signal(full)
Consumer
wait(full), wait(mutex), CS, signal(mutex), signal(empty)
Synchronizing consumer producer
Consumer wait will depend on producer signal. If empty is zero, will force producer to sleep until buffer empties.
Reader Writer problem
Only one process is allowed to write to a resource at a time but more than one is allowed to read from a process. If reading -> no process can write and vice versa.
Semaphore solution to read write - writer
wait(wrt), signal(wrt)
Semaphore solution to read write - reader
wait(mutex), readcount++, if readcount ==1 wait(wrt), signal mutex, read, wait(mutex), readcount–, if readcount ==0 signal(wrte), signal(mutex)
Critical Regions
High level solution to CS problem that removes programmer overhead.
Shared keyword
Critical region that allows for only one process to access the shared resource at a time
region v when B do S
region name when (boolean) do CS. If there is a simultaneous access the compiler will throw an error. When process leave S, all other programs reevaluate B.
region v when B do S for Consumer-Producer
B is space in the array (producer) and data to read (consumer)
Monitor
High level synchronization construct that allows for the safe sharing of data. Singleton class. Shared variables are set inside the monitor. Contains code to initialize variable, and procedure that represent to CS of various processes.
Condition variables
Cues declared in shared variable section. Operations of wait and signal are applied to the queues. x.wait means put on queue, sleep, and yield lock. It will not affect variable y
Signal in condition variables
When process executes x.signal and another process is waiting on x. First process goes to sleep until second process exits or waits. First process continues and executes. If another process wakes you up, you put that code to sleep, execute code, and then wake up another process.
Explain producer-consumer model for monitor
See picture
Prioritized waiting for monitor
X.wait(x) where x is an integer that will give priority on the queue for X
Java Synchronized methods
Synchronized keyword applied to method. Makes the method become a monitor. Must specify the object that acts as the lock in the parameters. Java’s synchronization does not explicitly require you to declare the shared variable within the block. Instead, the block synchronizes on the object instance specified in the synchronized keyword. Every object has an intrinsic lock
Java Producer Consumer
Notify -> signal but it wakes up everyone who was sleeping. One will wake up and the others will go back to sleep. Does not ensure priority over the latest to wait (no bounded wait). Only one condition variable is necessary because the buffer cannot be full and empty.
Processing Bursts
Most are short I/O, few are long CPU
Hyper exponential distribution
Length of bursts vs occurrences. Really short and long bursts are rare. See picture
Preemptive Scheduler
Takes itself off the CPU other than for I/O or finishing. Does not get switched at every interrupt
Dispatcher
Part of scheduler responsible for performing context switch and resuming process
Dispatch latency
Time for dispatcher to run
CPU utilization - sched criteria
Keep CPU as busy as possible
throughput - sched criteria
of jobs per unit of time
turnaround - sched criteria
Time of submission to completion
Wait time - sched criteria
Average amount of time in ready queue
Response - sched criteria
Submit time to output request (keystroke to terminal)
Simulation vs Implementation
Simulation involves trying out the different scheduling, which is hard to do. Implementation is try and find out which is expensive
Multiple processor queues
Usually a common queue for all processors. However, not every board has access to every I/O device.