Home > CS4310: Operating Systems > UnsortedUnsorted
TODO What came before?
TODO
struct {
Typedef int value;
struct process *list;
} semaphore;
(semaphore *S) {
wait-> value--;
S if (S -> value < 0) {
// add this process to S -> list
();
sleep}
}
(semaphore *S) {
signalif (S -> value <= 0) {
// remove process from S -> list
(P);
wakeup}
}
Basic system calls used:
Incorrect use of sempahore operations can cause deadlock and starvation.
Example: Misusing Semaphores
Interchanging Order
TODO
Replaces signal with wait
TODO
omits signal, wait, or both
TODO
High-level ADT that encapsulates data along with functions though which the data may be accessed and manipulated
Purpose: Guarantee mutual exclusion.
- Avoids lockout, deadlock, and starvation.
monitor monitor_name
{
// shared vars
procedure P1 (...) {...}
...
procedure Pn (...) {...}
initialization code (...) {...}
}
Deadlock: Two or more processes wait indefinitely for an event that can only be caused by only one of the waiting processes.
Starvation: Indefinite blocking
Priority Inversion: Scheduling problem when lower-priority process holds a lock needed by a higher-priority process.
Indivisibility: When we say a critical section must be indivisibly/atomically, we are talking about the code which holds and releases the lock.
- The critical section itself can be big and doesn’t need to be done in a single cycle, it can be preempted safely (though, this can lead to starvation).
Priority Inversion Protocol: We temporarily assign the highest priority to the process currently executing in its critical section to prevent it getting starved.
Suppose you have n buffers, each can hold one item.
TODO Code
do {
...
// produce iteme
...
}
Producer:
wait(empty)
: empty
will inform us if there is spacewait(mutex)
: Will inform us if we can write.signal(mutex)
: Release lock.signal(full)
: Increments full
.Consumer:
wait(full)
: Informs us if there is space.wait(mutex)
: Can we write?TODO Increment and decrement rules?