What is the shared memory concept by using producer consumer problem?


Inter process communication requires communicating to establish a shared memory region. A shared memory region is present in the address space for the process that creates the shared memory segment. And other processes are communicating using a shared memory segment that is attaching it to their address space.

Operating system prevents one process from accessing another process’s memory.

In shared memory two or more processes can exchange information by reading and writing data in shared memory areas. The processes are also responsible for ensuring that they are not writing to save location.

Producer-consumer problem

Now, let us discuss producer-consumer process problems.

Step 1 − A producer process produces information that is consumed by the consumer process. For example, a compiler that produces assembly code which is consumed by an assembler. The assembler can produce object modules which are consumed by the loader.

Step 2 − It uses the shared memory concept.

Step 3 − If we want to allow producer and consumer processes to run concurrently, we have to provide a buffer of items which can be filled by producer and empty the buffer by consumer.

Step 4 − This buffer will reside in a region of memory which is shared by producer and consumer process.

Step 5 − A producer can produce one item while the consumer is consuming another item.

Step 6 − The producer and consumer must be synchronised, so that the consumer does not try to consume an item which is not yet produced.

Types of buffer

There are two types of buffer which are as follows −

  • Unbounded buffer − It has no limit on the size of the buffer. The consumer may have to wait for new items, but the producer can always produce new items.

  • Bounder buffer − It assumed a fixed buffer size.

The consumer has to wait if the buffer is empty and the producer must wait if the buffer is full.

Given below is the structure of shared memory system

Updated on: 30-Nov-2021

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements