


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Department of Computer Sciences
Demonstrate the working of Peterson’s solution for process synchronization clearly identifying example scenarios to prove that it, does not violate mutual exclusion avoids/ has race condition avoid/ has starvation has/no busy wait avoids/leads to deadlock
The producer consumer problem (also known as the bounded buffer problem) is a problem in which two processes, the producer, and the consumer, share a single, fixed- size buffer that serves as a queue. Producer creates a product and places it in buffer. If the buffer is already full, the producer must wait for an empty block to appear in the buffer. A consumer consumes a buffer item. If the buffer is already empty, the consumer must wait for an item to be added to it. Use shared memory to implement Peterson's Algorithm for the two processes so that they mutually exclude each other. There should be no synchronisation issues in the solution. Explanation: does not violate mutual exclusion To synchronise two processes, Peterson's Algorithm is employed. It accomplishes this using two variables: a bool array flag of size 2 and an int variable turn. The Consumer is represented by I and the Producer is represented by j in the solution. The flags are initially false. When a process wishes to run its vital part, it sets its flag to true and becomes the index of another process. This indicates that the process wishes to run but will wait for the other process to finish first. The process is kept occupied while waiting for the other process to complete its own key part. The current process then starts its critical part when it adds or subtracts a random value from the shared buffer. Following the completion of the critical. avoids/ has race condition it avoids race condition avoid/ has starvation it avoid starvation has/no busy wait
environment in which threads are rapidly created and destroyed, but variance in the total number of threads in the system at any given time is small, can benefit from thread pools. Win 32 provides thread pools through the “pool function” function. Java also provides support for thread pools through java.util.concurrent package.
. In general, any environment during which threads are rapidly created and destroyed, but variance within the total number of threads within the system at any given time is tiny, can like thread pools Instead of creating and destroying ,the process simply queues the request of his pool of worker threads. Also several threads that spend their time in sleeping is replaced by single worker threads that awakens when event occurs.