8.process Synchronization
8.process Synchronization
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.2 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.3 Silberschatz, Galvin and Gagne ©2018
Process Synchronization
Process Synchronization Mode
(i) Serial Mode : only one process executed at a time. E.g ATM
Operating System Concepts – 10th Edition 6.4 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.5 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.6 Silberschatz, Galvin and Gagne ©2018
Critical Section Problem
Consider system of n processes {p0, p1, … pn-1}
Each process has critical section segment of code
• Process may be changing common variables, updating table,
writing file, etc.
• When one process in critical section, no other may be in its
critical section
Critical section problem is to design protocol to solve this
Each process must ask permission to enter critical section in entry
section, may follow critical section with exit section, then
remainder section
Operating System Concepts – 10th Edition 6.7 Silberschatz, Galvin and Gagne ©2018
Critical Section
Operating System Concepts – 10th Edition 6.8 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.9 Silberschatz, Galvin and Gagne ©2018
Critical-Section Problem (Cont.)
Requirements for solution to critical-section problem
Operating System Concepts – 10th Edition 6.10 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.11 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.12 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.13 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.14 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.15 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.16 Silberschatz, Galvin and Gagne ©2018
Synchronization Hardware
Many systems provide hardware support for implementing the
critical section code.
Uniprocessors – could disable interrupts
• Currently running code would execute without preemption
• Generally too inefficient on multiprocessor systems
Operating System Concepts – 10th Edition 6.17 Silberschatz, Galvin and Gagne ©2018
Hardware Instructions
Special hardware instructions that allow us to either
test-and-modify the content of a word, or to swap the
contents of two words atomically (uninterruptedly.)
• Test-and-Set instruction
• Swap instruction
Operating System Concepts – 10th Edition 6.18 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.19 Silberschatz, Galvin and Gagne ©2018
The TestAndSet Instruction
Definition
Properties
• Executed atomically
• Returns the original value of passed parameter
• Set the new value of passed parameter to true
Operating System Concepts – 10th Edition 6.20 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.21 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 6.22 Silberschatz, Galvin and Gagne ©2018