Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 6 : Synchronization (critical section (CS) problem (solutions…
Chapter 6 : Synchronization
critical section (CS) problem
to design protocol to solve
solutions
mutual exclusion
if P1 is executing in its critical section, then no other processes can be executing in their critical section
progress
if no process is executing, in CS & there exist some processes tht wish to enter their critical section, selection of the processes tht will enter CS next cannot be postponed indefinitly
bounded waiting
a bound must exist on no.of times tht other processes are allowed to enter their critical sections after a process has made a request to enter its critical & before tht request is granted
each process ask permission to enter critical section in
entry section
, may follow critical section wt
exit section
then
remainder section
to design protocol to solve the problem
each process has critical segment of code
:star:process may be changing common variables, updating table, writing file etc
:star:when one process in critical section, no other may be in its critical section
critical section handling in OS
preemptive
allow preemptive of process when running in kernel mode
non preemptive
runs until exits kernel mode, block or voluntarily yields CPU
synchronization hardware
uniprocessors - could disable interrupts
currently running code would execute without preemption
too inefficient on multiprocessor system
memory barriers
instruction tht forces any change in memory to be propagated (visible) to all other processors
memory model
strongly ordered - immediately visible
weakly ordered - not immediately visible
hardware instruction
allow us to either test and modify the content of a word, or swap the content of two words atomically
test and set instruction
compare and swap instruction
atomic variables
provide atomic updates on basic data types such as integers & boolean
increment() - ensures sequence is incremented without interruption
semaphores
synchronization tool tht provides more sophisticated ways for process to synchronize their activities
can be accessed via 2 invisible operations
wait()
signal()
usage
counting - integer value can range over an unrestricted domain
binary - integer value can range only btwn 0 and 1
implementation
must guarantee tht no 2 processes can execute wait() & signal() in the same sempahore at the same time
it will become the CS problem where the wait & signal code are placed in CS
no busy waiting
block - place the process involving the operation on appropriate waiting queue
wakeup - remove one of the processes in the waiting queue & place it into ready queue
monitors
high level abstraction provides convenient & effective mechanism for process synchronization
only one process may be active within the monitor at a time