Embed presentation
Downloaded 1,906 times









![PETERSON’S SOLUTION• To handle the problem of Critical Section (CS), Peterson gavean algorithm with a bounded waiting• Suppose there are N processes (P1, P2, … PN) and each ofthem at some point need to enter the Critical Section• A FLAG[] array of size N is maintained which is by default falseand whenever a process need to enter the critical section it hasto set its flag as true, i.e. suppose Pi wants to enter so it will setFLAG[i]=TRUE• There is another variable called TURN which indicates theprocess number which is currently to enter into the CS. Theprocess that enters into the CS while exiting would change theTURN to another number from among the list of readyprocesses10](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprocesssynchronization-151011113408-lva1-app6891%2f75%2fProcess-synchronization-in-Operating-Systems-10-2048.jpg&f=jpg&w=240)
![PETERSON’S SOLUTION11• If turn is 2 (say) then P2 enters the CS and while exitingsets the turn as 3 and thus P3 breaks out of wait loopFLAG[i] = false](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprocesssynchronization-151011113408-lva1-app6891%2f75%2fProcess-synchronization-in-Operating-Systems-11-2048.jpg&f=jpg&w=240)















![DINING PHILOSOPHERS PROBLEM• One possible solution, as shown in the following code section, is touse a set of five semaphores ( chopsticks[ 5 ] ), and to have eachhungry philosopher first wait on their left chopstick ( chopsticks[ i ] ),and then wait on their right chopstick ( chopsticks[ ( i + 1 ) % 5 ] )27](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprocesssynchronization-151011113408-lva1-app6891%2f75%2fProcess-synchronization-in-Operating-Systems-27-2048.jpg&f=jpg&w=240)








The document discusses process synchronization in operating systems, emphasizing the need for coordination among processes accessing shared resources to avoid issues like data inconsistency. It covers several solutions including semaphores, monitors, and atomic transactions while also addressing classical synchronization problems such as the producer-consumer and readers-writers problems. Additionally, it highlights the importance of managing critical sections and introduces challenges like deadlock and starvation that can arise during synchronization.









![PETERSON’S SOLUTION• To handle the problem of Critical Section (CS), Peterson gavean algorithm with a bounded waiting• Suppose there are N processes (P1, P2, … PN) and each ofthem at some point need to enter the Critical Section• A FLAG[] array of size N is maintained which is by default falseand whenever a process need to enter the critical section it hasto set its flag as true, i.e. suppose Pi wants to enter so it will setFLAG[i]=TRUE• There is another variable called TURN which indicates theprocess number which is currently to enter into the CS. Theprocess that enters into the CS while exiting would change theTURN to another number from among the list of readyprocesses10](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprocesssynchronization-151011113408-lva1-app6891%2f75%2fProcess-synchronization-in-Operating-Systems-10-2048.jpg&f=jpg&w=240)
![PETERSON’S SOLUTION11• If turn is 2 (say) then P2 enters the CS and while exitingsets the turn as 3 and thus P3 breaks out of wait loopFLAG[i] = false](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprocesssynchronization-151011113408-lva1-app6891%2f75%2fProcess-synchronization-in-Operating-Systems-11-2048.jpg&f=jpg&w=240)















![DINING PHILOSOPHERS PROBLEM• One possible solution, as shown in the following code section, is touse a set of five semaphores ( chopsticks[ 5 ] ), and to have eachhungry philosopher first wait on their left chopstick ( chopsticks[ i ] ),and then wait on their right chopstick ( chopsticks[ ( i + 1 ) % 5 ] )27](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fprocesssynchronization-151011113408-lva1-app6891%2f75%2fProcess-synchronization-in-Operating-Systems-27-2048.jpg&f=jpg&w=240)






