In C++ This exercise involves implementing the solution to the bounded buffer/readers and writers problem using threads. You will create a program that accepts four command line arguments: run_time...


In C++


This exercise involves implementing the solution to the bounded buffer/readers and writers problem using threads.


You will create a program that accepts four command line arguments:



  • run_time (the length of time the program should run)

  • buffer_size (number of slots in the bounded buffer)

  • num_producers (number of producer threads)

  • num_consumers (number of consumer threads)


The program will create a thread for each producer and consumer. As each thread produces or consumes a data item, it will print its status.


Example Output


Here are some sample runs:


Not enough arguments


If not enough arguments are provided, the program should print an error message and exit.


$ ./bounded_buffer Wrong number of arguments. Usage: bounded_buffer $

Invalid argument


If an argument is less than or equal to 0, the program should print a message and exit


$ ./bounded_buffer 10 5 1 0 ./bounded_buffer 10 5 1 0 num_consumers must be greater than 0 $

Correct Arguments


$ ./bounded_buffer 10 5 2 2 2: slept 2, produced 11 in slot 0 2: slept 1, consumed 11 in slot 0 1: slept 2, produced 79 in slot 1 1: slept 3, consumed 79 in slot 1 1: slept 1, produced 86 in slot 2 2: slept 1, consumed 86 in slot 2 1: slept 3, produced 58 in slot 3 2: slept 2, consumed 58 in slot 3 2: slept 5, produced 72 in slot 4 1: slept 3, consumed 72 in slot 4 1: slept 1, produced 92 in slot 0 2: slept 1, produced 86 in slot 1 1: slept 1, produced 74 in slot 2 2: slept 3, consumed 92 in slot 0 $




Jun 04, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here