The source code program

  • Bids0
  • Budget $0.00
  • Average Bid $0.00

Posted on

Active
Bid

Project Desciption

CMPSC 3113 Operating Systems

Assignment #2- Implementation of the Producer-Consumer ProblemNon-Threading implementation

In this assignment you are required to implement the Producer Consumer Problem as discussed in class.

Assume that there is only one Producer and there is only one Consumer.

  1. The problem you will be solving is the bounded-buffer producer-consumer problem. You are required to implement this assignment in Java or in C/C++. This buffer can hold a fixed number of items. This buffer needs to be a first-in first-out (FIFO) buffer. You should implement this as a Circular Buffer that satisfies the FIFO. There should be exactly one instance of the buffer. The producer and the consumers must reference the same buffer.
  2. The producer is responsible for producing data items to be added to the buffer. If the buffer is full, the producer must wait for a consumer to consume at least one item before it can add a new item to the buffer. The producer is required to produce a given number of items. The item that the producer adds to the buffer is a random uppercase letter ‘A’ to ‘Z’, inclusive. When a producer successfully inserts an item in the buffer it should print the location of insertion and time when insertion occurs with nanosecond resolution, using this format (spaces matter):Producer inserted ‘S’ at index 0 at 323187855 ns
  3. The consumer is responsible for consuming elements, generated by the producer, from the buffer. If the buffer is empty, the consumer must wait for the producer to add an item to the buffer. When a consumer successfully removes an item from the buffer it should print the location of removal and time when removal occurs with nanosecond resolution, using this format:Consumer consumed ‘I’ at index 7 at 324491579 ns
  4. Implement the Producer and the Consumer as two separate functions (no multithreading).
  5. The main driver (function) must do all necessary initialization, then it must iterate for a period of 10seconds (not 10 iterations).
  6. In each iteration, the main driver calls randomly either the Producer function or the Consumerfunction. Once either of these two functions is called, it should return within one second time period from the times that it has been called as specified below:If the corresponding function (Producer/Consumer) is successful in Producing/Consuming an item (character) before the one second is expired, then the function will return normally.Otherwise (in case of the Buffer is Full/Empty and the one second period has expired), then the corresponding function should return to the main driver without Producing/Consuming and item.
  7. Sample Output:
    Start time in nanosecond: 443727532 ns

Producer inserted ‘G’ at index 0 at 443729161 ns Producer inserted ‘Q’ at index 1 at 443730194 ns Producer inserted ‘R’ at index 2 at 443761114 ns Consumer consumed ‘G’ at index 0 at 443763544 ns Consumer consumed ‘Q’ at index 1 at 443769914 ns Consumer consumed ‘R’ at index 2 at 443774734 ns Producer inserted ‘E’ at index 0 at 443776594 ns Consumer consumed ‘E’ at index 0 at 443783544 ns Producer inserted ‘W’ at index 1 at 443785334 ns Producer inserted ‘U’ at index 2 at 443787024 ns Consumer consumed ‘W’ at index 1 at 443789048 ns Consumer consumed ‘U’ at index 2 at 443790011 ns…

8. What to submit:

  1. a) The source code program
  2. b) Instruction on how to compile and run this program
  3. c) Output of the program

Hint: The following might help you understand some time functions, try them.

#include <stdio.h> #include <time.h>

// main function to print the current time in nanosecondint main()

page2image10584{

}

struct timespec mytime; clock_gettime(CLOCK_REALTIME, &mytime);
double xyz = mytime.tv_nsec;
printf(“Time elpased since epoch is %.0f seconds\n”, xyz); return 0;

since epoch (or Unix time) is the

page2image13624// number of seconds that have elapsed since January 1, 1970 (midnight UTC/GMT)

page3image376

#include <stdio.h>
#include <time.h> // for clock_t, clock() #include <unistd.h> // for sleep()

#define BILLION 1000000000.0

// main function to find the execution time of a C program int main()
{

struct timespec start, end; clock_gettime(CLOCK_REALTIME, &start);

// do some stuff here
sleep(3); // sleep for three seconds

clock_gettime(CLOCK_REALTIME, &end);

// time_spent = end – start
double time_spent = (end.tv_sec – start.tv_sec) + (end.tv_nsec – start.tv_nsec) / BILLION;

printf(“Time elpased is %f seconds”, time_spent);

return 0; }

Employer Information

2315 project(s) posted hire 2 freelancers
Member since: 2020-02-01
FREELANCER BIDDING (0)

There are no bids yet.

Open chat
1
Whatapp Us
Hey? You want your project done, Whatsapp us Now.
Click to Submit a Project