Concurrency Control Flashcards
3 Concurrency contexts
- Multiple applications, process time shared 2. Structured applications 3. OS structures
Critical resources(CR)
Memory, shared I/O (printer), shared devices
Critical section (CS)
portion of program that uses critical resources
Concurrency Cases (3 broad activities)
- communication among processes 2. sharing and competing for resources 3. synchronization of activities of multiple processes
OS design and management issues of concurrency
- OS must be able to track active processes using PCB 2. OS allocate and deallocate resources for each process 3. OS must protect data and physical resources of each process against unintended interface by other processes 4, Results of process must be independent of speed of execution
how do processes interact
- unaware of each other 2. indirectly aware (share access to some I/O 3. directly aware of each other
principle strategies of concurrency
single processor - processes interleaved multiple processor, multiprogramming - processes overlapped
data coherence, consistency
maintenance of global variables and relationships between them
how do we maintain data coherence
sequential program execution
3 control problems of concurrency
- mutual exclusion - only one program at a time allowed 2. deadlocks - p1 has r1 needs r2; p2 has r2 needs r1 3, starvation - p1 has r1; p3 may get but p2 starved
requirements for ME (mutual exclusion)
- ME must be enforced 2. Process that halts in non CS must do so without interfering with other processes 3. Process requiring CS can’t be delayed indefinitely 4. When no process in CS, process that requests entry must be allowed to enter 5. No assumptions about relative process speeds or number of processes 6. Process remains inside CS for finite time delay
implementation of ME 3 approaches
software approach special purpose machine instructions (turn, test and set) semaphores
1st software approach to ME implementation (turn)
address reserved for turn shared variable Process 0 Process 1 while (turn != 0) ….. /*do nothing*/; while (turn != 1) /*CS*/ /* do nothing*/; turn = 1; /*CS*/ turn = 0;
analysis of turn approach
ME guaranteed with problems toggle issue - processes strictly alternate, pace dictated by slower if one process fails, other stalls
2nd software approach to ME (Boolean flags)
flag[0] for P0; if TRUE, it’s in CS flag[1] for P1 if FALSE not in CS reset own flag after leaving CS each process may examine other’s flag (not change it)