1 / 17

Effective Mutual Exclusion Protocols in Process Synchronization

Learn about critical section problems, process entry/exit protocols, non-critical sections, and various algorithms ensuring correctness and efficiency in concurrent computing systems.

mchong
Download Presentation

Effective Mutual Exclusion Protocols in Process Synchronization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 720 Mutual Exclusion

  2. Critical Section problem • Process i do (true) entry protocol; critical section; exit protocol; non-critical section od

  3. Correctness • Mutual exclusion: at most one process at a time is executing its critical section • Absence of deadlock: If two or more processes are trying to enter their critical section, at least one will succeed • Absence of unnecessary delay: If a process is trying to enter its critical section and the other processes are executing their non-critical sections or have terminated then the first process is not prevented from entering its critical section. • Eventual entry: A process that is attempting to enter its critical section will eventually succeed.

  4. Invariant based approach CS1 CS2 do (true) do (true)  entry protocol; entry protocol; in1 = true in2 = true critical section critical section exit protocol; exit protocol; in1 = false in2 = false non-critical section non-critical section od

  5. Invariant based approach CS1 CS2 do (true) do (true)  <await (!lock)  lock = true> <await(!lock)  lock = true> critical section critical section lock = false lock = false non-critical section non-critical section od

  6. Test and set instruction CS1 CS2 do (true) do (true)  while (TS(lock)) skip; while(TS(lock)); critical section critical section lock = false lock = false non-critical section non-critical section od

  7. Implementing await statements • CSenter while (!B) { CSexit; CSenter } S; CSexit

  8. Tie Breaker Algorithm in1 = false; in2 = false; last = 1 co CS1: CS2: do true  do true  int = true; last = 1; in2 = true; last = 2; while(in2 /\ last == 1); while(in1 /\ last == 2); critical section critical section in1 = false; in2 = false; non-critical section non-critical section od od oc

  9. Tie Breaker Algorithm in1 = false; in2 = false; last = 1 co CS1: CS2: do true  do true  last = 1; in1 = true; last = 2; in2 = true <await (!in2 \/ last == 2)>; <await (!in1 \/ last == 1)>; critical section critical section in1 = false; in2 = false; non-critical section non-critical section od od oc

  10. Ticket Algorithm next = 1; number = 1; turn[1..n]= [0…0]; co CSi: do true  < turn[i] = number; number = number + 1 > await( turn[i] ) == next critical section <next = next + 1> non-critical section od oc Invariant: next > 0 and for all i, cs[i] in CS  turn[i] == next /\ turn[i] != turn[j] for all j

  11. Bakery algorithm turn1 = 0; turn2 = 0; co CS1: CS2: do true  do true  turn1 = turn2 + 1; turn2 = turn1 + 1 while(turn2 != 0 /\ turn1 > turn2); while(turn1 != 0 and /\ turn2 > turn1); critical section critical section turn1 = 0; turn2 = 0; non-critical section non-critical section od od oc

  12. Bakery algorithm turn1 = 0; turn2 = 0; co CS1: CS2: do true  do true  turn = 1; turn2 = 1 turn1 = turn2 + 1; turn2 = turn1 + 1 while(turn2 != 0 /\ while(turn1 != 0 and /\ (turn1,1) > (turn2,2)); (turn2,2) > (turn1,1)); critical section critical section turn1 = 0; turn2 = 0; non-critical section non-critical section od od oc

  13. Barrier synchronization Worker[i]: do true  code for task i wait for all tasks to complete od

  14. Barrier synchronization Worker[i]: do true  code for task i <count = count + 1> < await( count == n) > od

  15. Barrier synchronization Worker[i]: do true  code for task i <count = count + 1> < await( count == n) > od

  16. Barrier synchronization co worker[i]: Coordinator do true  do true  code for task I; for (i = 1 to n) arrive[i] = 1 await(arrive[i]= 1); await(continue ==1) continue = 1 od od oc

  17. Barrier synchronization co worker[i]: Coordinator do true  do true  code for task I; for (i = 1 to n) arrive[i] = 1 { await(arrive[i]= 1); await(continue[i]==1) arrive[i] = 0; } continue[i] = 0; for (i = 1 to n) continue[i] = 1 od od oc Flag rule: A process that waits for the synchronization flags should reset it.

More Related