Process Synchronization
Process Synchronization
data.
✓Each process must request permission to enter its critical section. The section
of code implementing this request is the entry section. The critical section may
threads that may be trying to access same resource like memory or I/O etc. to
✓Only one thread at a time can take the ownership of a mutex and apply the
lock. Once it done utilizing the resource and it may release the mutex lock.
MUTEX HIGHLIGHTS
➢Mutex is very different from Semaphores
1. Mutex is binary in nature
1. WAIT
2. SIGNAL
THERE ARE TWO TYPES OF SEMAPHORES :
Semaphore can have two different operations which are wait and
signal. In some books wait signals are also denoted by P(s) and signal
by V(s). Where s is a common semaphore.
Signal(s) {
s++;
}
WAIT OPERATIONS
wait(s) {
while(s <= 0) ;
s--;
}
➢Actual working for both functions together to achieve access of critical
section
// some code
wait(s);
// critical section code
signal(s);
// remainder code
The eventual goal is to protect the critical section code using wait and
signal operations.
To visualize the whole operation on how the semaphore system works
with the example below :
➢ FOR COUNTING SEMAPHORE
➢Readers – Readers are those processes/users which only read the data
➢Writers – Writers are those processes which also write, that is, they
change the data
But if one Writer (say W1) is editing or writing the file then it should locked
and no other writer (say W2) can make any changes until W1 has finished
1. Writer wants the access to critical section i.e wants to perform the writing
2. First wait(wrt) value is checked
1. If returns true then gets access
1. Does the write process
2. Performs signal(wrt) and increments value
2. If returns false then
1. Does not get write access
READER PROBLEM
READER SECTION
WRITER
needed by scheduler.
THE SOLUTION TO READER – WRITER PROBLEM
• Initialized as 0
PRODUCER PROBLEM SOLUTION CONSUMER PROBLEM SOLUTION
PROCESS SYNCHRONIZATION
Problem Statement
for a philosopher then only he should pick even philosopher must pick his right and off must