Chap4_OS
Chap4_OS
(Process Synchronization)
Module 4: Process Synchronization
Background
The Critical-Section Problem
Software solutions
Dekker’s solution
Peterson’s Solution
Hardware Solution
Interprocess Communication
Algorithm#2:
Repeat
flag[i]=true;
While flag[j]……..do no-op
Critical Section
…………..
flag[i]=false;
Remainder Section
Until false
do {
flag[i] = TRUE;
turn = j;
while ( flag[j] && turn == j);
CRITICAL SECTION
flag[i] = FALSE;
REMAINDER SECTION
} while (TRUE);
// critical section
lock = FALSE;
// remainder section
} while ( TRUE);
P2 P2 P3 ... P4
m
m m m
P1 P1
Shared memory
message
P
mbox R
Q
P or Q call
send(mbox-id, message)
R calls
receive(mbox-id, message)