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:

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
Topic Video
Question

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 <run_time> <buffer_size> <num_producers> <num_consumers> $

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 $

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Instruction Format
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
  • SEE MORE 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