/
CIS 720 Mutual Exclusion 2 CIS 720 Mutual Exclusion 2

CIS 720 Mutual Exclusion 2 - PowerPoint Presentation

alida-meadow
alida-meadow . @alida-meadow
Follow
343 views
Uploaded On 2019-11-22

CIS 720 Mutual Exclusion 2 - PPT Presentation

CIS 720 Mutual Exclusion 2 Tie Breaker Algorithm in1 false in2 false last 1 co CS1 CS2 do true do true last 1 in1 true last 2 in2 true ID: 766885

true region section critical region true critical section arrive start task await barrier synchronization cs1 cs2 in2 in1 exclusion

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "CIS 720 Mutual Exclusion 2" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

CIS 720 Mutual Exclusion 2

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

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

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

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

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

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.

Invariant based approach Identify synchronization regions in your program Synchronization region: segment of code or control point at which a thread must wait for another thread or signal another thread.

Mutual exclusion CS1 CS2 do (true)  do (true)  ****start of region **** start of region critical section critical section **** end of region **** end of region non-critical section non-critical section od

Mutual exclusion CS1 CS2 do (true)  do (true)  ****start of region **** start of region in 1 = in 1 + 1 in 2 = in2 + 1 critical section critical section **** end of region **** end of region out1 = out1+1; out2 = out2+1; non-critical section non-critical sectionodAssociate in and out counter with each region

Mutual exclusion CS1 CS2 do (true)  do (true)  ****start of region **** start of region in 1 = in 1 + 1 in 2 = in2 + 1 critical section critical section **** end of region **** end of region out1 = out1+1; out2 = out2+1; non-critical section non-critical sectionodAssociate in and out counter with each region Write an invariant using in and out counters I = (in 1 =out 1 ) \/ (in2=out2)

Mutual exclusion CS1 CS2 do (true)  do (true)  ****start of region **** start of region <await(in 2 =out 2 ) in1 = in1 + 1> <await(in1=out1) in2 = in2 + 1> critical section critical section **** end of region **** end of region out1 = out1+1; out 2 = out 2 +1; non-critical section non-critical section od Associate in and out counter with each regionWrite an invariant using in and out countersI = (in1 =out 1 ) \/ (in 2 =out 2 ) Derive guards for the increment assertions

Barrier Synchronization P1 P2 do (true)  do (true)  task for p1 task for p2 ****start of region **** start of region **** end of region **** end of region od

Barrier CS1 CS2 do (true)  do (true)  task for p1 task for p2 ****start of region **** start of region arrive 1 = arrive 1 + 1 arrive2 = arrive2 + 1 **** end of region **** end of region depart1 = depart1+1; depart2 = depart2+1;odAssociate counters with each region

Barrier CS1 CS2 do (true)  do (true)  task for p1 task for p2 ****start of region **** start of region arrive 1 = arrive 1 + 1 arrive2 = arrive2 + 1 **** end of region **** end of region depart1 = depart1+1; depart2 = depart2+1;odAssociate counters with each region Write an invariant using the counters (depart[1] <= arrive[2]) /\ (depart[2] <= arrive[1])

Semaphores Two operations: P(s), V(s) Semaphore invariant: nP = number of P operations invoked so far nV = number of V operations invoked so far init = initial value of s nP <= nV + init

Let s = nV + init – nP Invariant: s >= 0 P(s): nP = nP + 1 <await s > 0  s = s - 1> V(s): nV = nV + 1 < s = s + 1> Binary semaphore: 0 <= s <= 1

Mutual exclusion CS i do (true)  in[i] = 1 critical section in[i] = 0 non-critical section od I = ( 0 <= (in[1] + in[2] + …. + in[n]) <= 1 ) Let mutex = 1 - (in[1] + in[2] + …. + in[n]) I = ( 0 <= mutex <= 1 )

Mutual exclusion CS i do (true)  critical section non-critical section od I = ( 0 <= (in[1] + in[2] + …. + in[n]) <= 1 ) Let mutex = 1 - (in[1] + in[2] + …. + in[n]) I = ( 0 <= mutex <= 1 )

Barrier CS1 CS2 do (true)  do (true)  task for p1 task for p2 ****start of region **** start of region arrive 1 = arrive 1 + 1 arrive2 = arrive2 + 1 **** end of region **** end of region depart1 = depart1+1; depart2 = depart2+1;odBarrier1 = (arrive 1 – depart 2 ) Barrier2 = (arrive 2 – depart 1 )

Barrier CS1 CS2 do (true)  do (true)  task for p1 task for p2 barrier1++ barrier2++ barrier2--; barrier1--; od Barrier1 = (arrive 1 – depart2)Barrier2 = (arrive2 – depart1)