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:
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
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
- 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
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education