The circular buffer should be placed in shared memory so that each process can access the buffer to support inter-process communication. The following code snippets can be used as guidance for implementing a shared memory buffer. Your objective is to implement the shared circular buffer along with put() and get() functions to access the buffer. Each process function (i.e., producer() and consumer()) will access the circular buffer where your objective is to ensure that the producer is always ahead of the consumer and the consumer does not have to wait. This is illustrated in the following diagram: (Image below) Signals should be used between the two processes. The consumer should put itself to sleep if there is no data in the buffer and wait for a signal from the producer indicating data has been placed in the buffer. The producer should put itself to sleep if the buffer is full and wait for a signal from the consumer that there is room in the buffer to start writing again. An explanation of your approach to implementation and its reasoning. Coding results: All the source code files. Comment your code, describing the solution and identifying the programmer. Screenshots showing successful and correct execution of the code.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

The circular buffer should be placed in shared memory so that each process can access the buffer to support inter-process communication. The following code snippets can be used as guidance for implementing a shared memory buffer.

Your objective is to implement the shared circular buffer along with put() and get() functions to access the buffer. Each process function (i.e., producer() and consumer()) will access the circular buffer where your objective is to ensure that the producer is always ahead of the consumer and the consumer does not have to wait. This is illustrated in the following diagram:

(Image below)

Signals should be used between the two processes. The consumer should put itself to sleep if there is no data in the buffer and wait for a signal from the producer indicating data has been placed in the buffer. The producer should put itself to sleep if the buffer is full and wait for a signal from the consumer that there is room in the buffer to start writing again.

An explanation of your approach to implementation and its reasoning.

Coding results:

    1. All the source code files. Comment your code, describing the solution and identifying the programmer.
    2. Screenshots showing successful and correct execution of the code.
producer
buffer
consumer
Transcribed Image Text:producer buffer consumer
// Shared Circular Buffer
struct CIRCULAR_BUFFER
{
int count;
int lower;
int upper;
int buffer[100];
// Number of items in the buffer
// Next slot to read in the buffer
// Next slot to write in the buffer
};\_\
struct CIRCULAR_BUFFER *buffer = NULL;
// Create shared memory for the Circular Buffer to be shared between the Parent and Child Processes
buffer= (struct CIRCULAR_BUFFER*)mmap(0, sizeof (buffer), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
buffer->count = 0;
buffer->lower = 0;
buffer->upper = 0;
Transcribed Image Text:// Shared Circular Buffer struct CIRCULAR_BUFFER { int count; int lower; int upper; int buffer[100]; // Number of items in the buffer // Next slot to read in the buffer // Next slot to write in the buffer };\_\ struct CIRCULAR_BUFFER *buffer = NULL; // Create shared memory for the Circular Buffer to be shared between the Parent and Child Processes buffer= (struct CIRCULAR_BUFFER*)mmap(0, sizeof (buffer), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); buffer->count = 0; buffer->lower = 0; buffer->upper = 0;
Expert Solution
steps

Step by step

Solved in 6 steps with 1 images

Blurred answer
Knowledge Booster
Analysis of Performance Measurement
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education