| Process unaware of each other | Competition |Results of one independent of others, timing might be affected | Mutual exclusion, Deadlock (renewable resource), starvation|
| Processes indirectly aware of each other | Cooperation by sharing|Results of one may depend on info obtained by others, timing may be affected | Mutual exlusion, deadlock (renewable resource), starvation, data coherence |
| Process directly aware of each other | " by communication | Results of one process may depend on info obtained on others, time may be affected | Deadlock(consumable resource), starvation |
---
Concepts for competition for resources
- Mutual exclusion
- Critical sections
- only one program at a time allowed in the section
- e.g. one process at a time is allowed to send command to the printer
- Deadlock
- Starvation
### Mutual Exclusion
Requirements for MutEx:
1.**Enforcement** Only one process at a time is allowed in the critical section
for a resource
2. A process that halts in its noncritical section must do so without interfering
with other processes
3. No deadlock or starvation
4. A process must not be delayed to a critical section when there is no other
process using it
5. No assumptions are made about relative process speeds or number of processes
6. A process remains inside its critical section for a finite time only
Mechanisms:
- Software: **Dekker's Algorithm** (and many others)
- Requires no special instructions
- Highly portable
- Slow
- Hardware: Special instructions on ISA
Hardware Support:
- Interrupt disabling as a means for mutex:
- A process runs until it invokes an OS service or until it is interrupted
- Disabling interrupts guarantees mutex in a uniprocessor system
- Porcessor is limited in its ability to interleave programs
- Special Machine instructions:
- Performed in a single instruction cycle
- Access to the memory ocation is blocked by any other instructions
Advantages of hardware implementatino:
- Applicable to any number of processes on either a single or multi processors
sharing memory
- It is simple, and therefore easy to verify
- It can be used to support multiple critical sections
Disadvantages:
- Busy-waiting consumes processor time
- Starvation is possible when a process leaves a critical section and more than
one process is waiting
- Deadlock (if a low priority process has the critical region and a higher prio
needs, the higher prio process will obtain the processor to wait for the
critical region
- Pipeline stalls
### Advanced Concurrency Control Mechanisms
**Semaphores**: a concurrency control mechanism based on a special variable used
for signalling.
- If a process is waiting for a signal, it is suspend until that signal is sent
- Semaphore is a variable that has an integer value
- May be initialized to be nonnegative
- Wait operation decrements the value (`semWait() )
- Signal operation increments it (`semSignal()`)
- *No other way to access the semaphore*
- In general, anyone can call `semWait()` and `semSignal()`
- For a mutex, only the process with the lock can release the lock