Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Skeleton of buffer.c Problem Statement: Read through Project 3 (page 253-255) in the textbook, the Producer-Consumer Problem, and finish it using Pthreads only (ignore the

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Skeleton of buffer.c

image text in transcribed

image text in transcribed

Problem Statement: Read through Project 3 (page 253-255) in the textbook, the Producer-Consumer Problem, and finish it using Pthreads only (ignore the Windows API part). Your project must meet the following requirements for full credit 1. Instead of generating random numbers and write to the buffer, producer threads will write incremental integers into the buffer. For example, if the initial value of the number is 10, then the next number should be 11, and the next will be 12 2. Create producer and consumer threads with 3 scenarios and show your results in screenshots similar as the sample screenshots shown below. The three scenarios are: 1) more producers than consumers; 2) more consumers than producers; 3) same number of producers and consumers. Please refer to the screenshots shown below for sample outputs under different scenarios. (Your outputs may be different) 3. The main O function will be passed four parameters on the command line. The four parameters are 1. 2. How long will the main thread sleep before terminating T 3. 4. he number of producer threads The number of consumer threads The initial value of the number (for producers) Your program should be executed like this /buffer . Here buffer is your executable file which is followed by four parameters, sleep time, the number of producer threads, the number of consumer threads, and the initial number. Eg. ./buffer 10 2 2 10 Some Notes: 1. To help you to get started, a skeleton of the buffer.c is provided in iCollege. 2. To get a thrcad's ID, you may call the pthrcad sclf) function and convert the result into an integcr. Bclow is a samplc showing how a thrcad can get and print its ID printf("Consumer %u consumed %d " ,(unsigned int)pthread self(), random); 3. Using gec -pthread -o buffer buffer.c to compile, and then an executable file buffer would be generated. (Suppose buffer.c is your code file) Problem Statement: Read through Project 3 (page 253-255) in the textbook, the Producer-Consumer Problem, and finish it using Pthreads only (ignore the Windows API part). Your project must meet the following requirements for full credit 1. Instead of generating random numbers and write to the buffer, producer threads will write incremental integers into the buffer. For example, if the initial value of the number is 10, then the next number should be 11, and the next will be 12 2. Create producer and consumer threads with 3 scenarios and show your results in screenshots similar as the sample screenshots shown below. The three scenarios are: 1) more producers than consumers; 2) more consumers than producers; 3) same number of producers and consumers. Please refer to the screenshots shown below for sample outputs under different scenarios. (Your outputs may be different) 3. The main O function will be passed four parameters on the command line. The four parameters are 1. 2. How long will the main thread sleep before terminating T 3. 4. he number of producer threads The number of consumer threads The initial value of the number (for producers) Your program should be executed like this /buffer . Here buffer is your executable file which is followed by four parameters, sleep time, the number of producer threads, the number of consumer threads, and the initial number. Eg. ./buffer 10 2 2 10 Some Notes: 1. To help you to get started, a skeleton of the buffer.c is provided in iCollege. 2. To get a thrcad's ID, you may call the pthrcad sclf) function and convert the result into an integcr. Bclow is a samplc showing how a thrcad can get and print its ID printf("Consumer %u consumed %d " ,(unsigned int)pthread self(), random); 3. Using gec -pthread -o buffer buffer.c to compile, and then an executable file buffer would be generated. (Suppose buffer.c is your code file)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions