小 Mutual Exclusion(P193) B Critical resource: Only one process can access it at a time Critical section: the portion of the program that uses critical resource entry section critical secion exit section PROCESSES AND SCHEDULING
PROCESSES AND SCHEDULING Mutual Exclusion(P193) ❖ Critical resource: Only one process can access it at a time. ❖ Critical section:the portion of the program that uses critical resource. entry section critical section exit section
P194,fig5.1 Program mutualexclusion Begin(main progra Const n-.; * num of processes) parbegin Procedure P(i: integer) Begin p2; repea enter critical(r) png aren <critical section>: pa End exit critical(R <remainder> orever End PROCESSES AND SCHEDULING
PROCESSES AND SCHEDULING P194,fig5.1 Program mutualexclusion Const n-…; (*num of processes) Procedure P(i:integer) Begin repeat enter critical(R) <critical section>; exit critical(R) <remainder> forever End; Begin(*main program*) parbegin p1; p2; … pn; parend End
Deadlock and Starvation(P194) Deadlock Exp. Two processes Pl, P2, both request to resource riv R2. At a time: PI gets R2 and p2 gets rl, in the meantime pl requests RI and p2 requests r2 s Then pi and p2 wait for each other forever -deadlock. ☆ Starvation Pl always communication with P2, p3 is starved PROCESSES AND SCHEDULING
PROCESSES AND SCHEDULING Deadlock and Starvation(P194) ❖ Deadlock ٭ Exp. Two processes P1、P2, both request to resource R1、 R2. At a time: ٭ P1 gets R2 and P2 gets R1, in the meantime P1 requests R1 and P2 requests R2 ٭ Then P1 and P2 wait for each other forever ---deadlock. ❖ Starvation ٭ P1 always communication with P2, p3 is starved
Cooperation among Processes by Sharing(p195) ☆ Data integrity s Reading and writing, and only writing operations must be exclusive Data coherence: a=b no longer holds P1:a:=a+1 a:=a+1 b:=b+1 b:=2b P2:b:=2*b b:=b+1 a:=2a a:=2*a PROCESSES AND SCHEDULING
PROCESSES AND SCHEDULING Cooperation among Processes by Sharing(p195) ❖ Data integrity ٭ Reading and writing, and only writing operations must be exclusive. ❖ Data coherence: a=b no longer holds P1: a:=a+1 b:=b+1 P2: b:=2*b a:=2*a a:=a+1 b:=2*b b:=b+1 a:=2*a
Cooperation among Processes by Communication Synchronize: The processes send and receive data between each other coordinately. PROCESSES AND SCHEDULING
PROCESSES AND SCHEDULING Cooperation among Processes by Communication ❖ Synchronize: The processes send and receive data between each other coordinately