Monday, January 29, 2007

OS 4

How much does blocking cost?
How long should you spin?
Spin for the length of the block cost. If you still don't have the lock, then block.
Idea is to pay the incremental cost until it equilibrates with the up-front cost, then switch.
Mutual Exclusion -- only have one process at a time in the critical section.
Make Progress
Multiple threads that are sharing state info create race conditions.
While (lock is not available)
spin - within your own process cache
...
What is the good, bad, and ugly of recursive locks?
What is synchronization modularity?
What characterizes trylocks?

Producer/Consumer design pattern
producer puts characters in an infinite buffer
consumers pulls characters out...
not so edge case of consumer reading to read while producer has fallen behind
release lock, go to sleep?
producer should wakeup the consumer as it posts a char.
Semaphores - non-negative integer counter with atomic increment and decrement. Semaphores block rather than going negative. Use semaphores for mutual exclusion and scheduling.
Emulate a lock using semaphores.
Monitors are easier and safer than semaphores.
Think about Java synchornized classes as monitors.
What is the difference between Hoare semantics and Mesa semantics?

No comments: