Docsity

Implementing Peterson's Algorithm for Producer-Consumer Problem, Schemes and Mind Maps of Machine Learning

Toggle sidebar
bg1
Bahria University
Lahore Campus
Department of Computer Sciences
Assignment # 3
Name:
Abdul Sayyam
Mohammad Hamid Azeem
Roll No:
03-135202-001
03-135202-030
Submission Date: 9th.06.2022
Instructor Name: Sarah Chaudhry Program/Semester: BS (IT) - 4
Course Title: Operating System Max Marks: 15
Question No 1 [5 Marks]
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
1
pf3
pf4

Partial preview of the text

Download Implementing Peterson's Algorithm for Producer-Consumer Problem and more Schemes and Mind Maps Machine Learning in PDF only on Docsity!

Bahria University

Lahore Campus

Department of Computer Sciences

Assignment # 3

Name:

Abdul Sayyam

Mohammad Hamid Azeem

Roll No:

Submission Date: 9th.06.

Instructor Name: Sarah Chaudhry Program/Semester: BS (IT) - 4

Course Title: Operating System Max Marks: 15

Question No 1 [5 Marks]

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

ANSWER:

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.