slides07 - Synchronization Techniques Flashcards
1
Q
Concurrent processes
A
Processes that are aware of each other and directly or indirectly work together and may affect the execution of the other
2
Q
Race conditions & how to avoid them
A
- When two or more processes are reading/writing shared data and final result depends on who runs first
- Avoid them by prohibiting more than one process reading/writing shared data at the same time - mutual exclusion
3
Q
Critical section
A
- Part of program that accesses shared data
- No two processes should be in their CS at the same time
4
Q
Requirements of a CS
A
- No two processes may simultaneously be in their CS
- No assumptions be made about speeds or number of CPUs
- No process running outside its CS may block other processes
- No process should have to wait forever to enter its CS
5
Q
Implementing CS using lock variable
A
- if lock == 0 set lock = 1 and enter_CS; if lock == 1 wait until lock becomes 0
- does not work because its still a shared variable
6
Q
Strict alternation
A
- Two processes take turns entering CS using global variable set to either 1 or 0 (global variable switched after program exists its CS)
- Drawback: can lead to starvation (one process waiting indefinitely for the other process thats not in its CS)
7
Q
Peterson’s Algorithm
A