Week 8,9
Week 8,9
SYNCHRONIZATION
USMAN AZIZ
OUTLINE
• To ensure that the Producer should not add DATA when Buffer is full
and Consumer should not take the data when Buffer in empty
SOLUTION OF THE PROBLEM
• To handle the problem of Critical Section (CS), Peterson gave an algorithm with a
bounded waiting.
• Suppose there are N processes (P1, P2, ..PN) and each of them at same point need to
enter the Critical Section.
• A FLAG[] array of size N is maintained which is by default is false and whenever a
process need to enter the critical section, it has be to be set its flag as true, i.e.
suppose Pi wants to enter so it will set FLAG[i]=TRUE.
• There is another variable called TURN which indicated the process number which is
currently to enter in the CS while exiting would change the TURN to another number
from among the list of ready processes.
SYNCHRONIZATION HARDWARE
• It’s simple.
• Works with many processes.
• Can have many different critical sections with different semaphores.
• Each critical section has unique access semaphores.
• Can permit multiple processes into the critical section as once, if
desirable.
DEADLOCKS
• One problem that can arise when using semaphore to block processes
waiting for a limited resources is the problem deadlocks, which occur
when:
• Multiple processes are blocked, each waiting for a resource that can
only be freed by one of the other (blocked) processes as shown:
STARVATION
• In which one or more processes gets blocked forever and never get a
chance to take their turn in critical section.
• For example: in semaphores above, we did not specify the algorithms
for adding processes to the waiting queue in semaphore in wait() call,
or selecting one to be removed from the queue in the signal() call.
• If the method chosen is FIFO queue, then every process will eventually
get their turn, but if LIFO queue is implemented, then the first process
to start waiting could starve.
THANK YOU