●●● ●●●● 6.3 Peterson's solution ●●●●● ●●●● ●●0●● ●●●● Algorithm 3 (Peterson 1981) ●●●● Process p do i flag[]= true; turn while(flag d]=true & turn==j) critical section flag [] false remainder section 3 while(ture
22 6.3 Peterson’s Solution ⚫ Algorithm 3 (Peterson 1981) ⚫ Process Pi do { flag [i] = true; turn = j; while (flag [j]==true && turn == j) ; critical section flag [i] = false; remainder section } while (ture);
●●● ●●●● 6.3 Peterson's solution ●●●●● ●●●● ●●0●● ●●●● ● Process P ●●●● do t flag的=true; turn=i while flag [==true & turn ==i); critical section flag [] false; remainder section 3 while(ture) o Meets all three requirements; solves the critical-section problem for two processes
23 6.3 Peterson’s Solution ⚫ Process Pj do { flag [j] = true; turn = i; while (flag [i]==true && turn == i) ; critical section flag [j] = false; remainder section } while (ture); ⚫ Meets all three requirements; solves the critical-section problem for two processes
●●● ●●●● 6. Process synchronization 9989 ●●●0 ● Question ●●●● Block in critical-section o Interrupt process scheduling in critical- section
24 6. Process synchronization ⚫ Question ⚫ Block in critical-section ? ⚫ Interrupt / process scheduling in criticalsection ?
●●● ●●●● 6. Process synchronization 9988 ●●●● e 6.1 Background ●●●● o 6.2 The Critical-Section Problem o 6.3 Peterson's solution 6.4 Synchronization Hardware 6.5 Semaphores o 6.6 Classic Problems of synchronization ●67 Monitors e 6.8 Synchronization Examples o 6.9 Atomic transactions
25 6. Process synchronization ⚫ 6.1 Background ⚫ 6.2 The Critical-Section Problem ⚫ 6.3 Peterson’s Solution ⚫ 6.4 Synchronization Hardware ⚫ 6.5 Semaphores ⚫ 6.6 Classic Problems of Synchronization ⚫ 6.7 Monitors ⚫ 6.8 Synchronization Examples ⚫ 6.9 Atomic Transactions
●●● ●●●● 6.4 Synchronization Hardware aos ●●●● Lock( essential solution model ●●●● A process must acquire a lock before entering a critical section o release the lock when it exits the critical section do i acquire lock critical section release lock remainder section 3 while(TRUe) The design of such locks can be quite sophisticated(需要丰富的经验)
26 6.4 Synchronization Hardware ⚫ Lock (essential solution model) ⚫ A process must ⚫ acquire a lock before entering a critical section ⚫ release the lock when it exits the critical section ⚫ do { acquire lock critical section release lock remainder section } while (TRUE); ⚫ The design of such locks can be quite sophisticated(需要丰富的经验)