Process Synchronisation and Producer Consumer Problem Operating System

1,033 views 6 slides Nov 26, 2023
Slide 1
Slide 1 of 6
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6

About This Presentation

Presentation on Process Synchronisation and Producer Consumer Problem | Operating System| Computer Science Engineering| Anjuman College of Engineering and Technology


Slide Content

Process Synchronization Processes Synchronization or Synchronization is the way by which processes that share the same memory space are managed in an operating system. It helps maintain the consistency of data by using variables or hardware so that only one process can make changes to the shared memory at a time. For example- Inconsistency of data can occur when various processes share a common resource in a system which is why there is a need for process synchronization in the operating system.

★ How Process Synchronization in OS Works ? Let us take a look at why exactly we need Process Synchronization. For example, If a process1 is trying to read the data present in a memory location while another process2 is trying to change the data present at the same location, there is a high chance that the data read by the process1 will be incorrect. Advantages of Process Synchronization Ensures data consistency and integrity Avoids race conditions Prevents inconsistent data due to concurrent access Supports efficient and effective use of shared resources

PRODUCER — CONSUMER PROBLEM → Also known as Bounded – Buffer Problem → The Producer-Consumer problem is a classic synchronization problem in operating systems. → There is a fixed-size buffer and a Producer process, and a Consumer process. → The Producer process creates an item and adds it to the shared buffer. → The Consumer process takes items out of the shared buffer and “consumes” them. The Problem – The Producer process must not produce an item if the shared buffer is full. The Consumer process must not consume an item if the shared buffer is empty. Access to the shared buffer must be mutually exclusive; this means that at any given instance, only one process should be able to access the shared buffer and make changes to it.

Solution of Producer – Consumer Problem To solve the Producer-Consumer problem three semaphores variable are used : Semaphores are variables used to indicate the number of resources available in the system at a particular time. Semaphore variables are used to achieve `Process Synchronization. Full The full variable is used to track the space filled in the buffer by the Producer process. It is initialized to 0 initially as initially no space is filled by the Producer process. Empty The Empty variable is used to track the empty space in the buffer. The Empty variable is initially initialized to the BUFFER-SIZE as initially, the whole buffer is empty. Mutex Mutex is used to achieve mutual exclusion. Mutex ensures that at any particular time only the producer or the consumer is accessing the buffer. Mutex is a binary semaphore variable that has a value of 0 or 1.

T hank Y ou