buffer size and pthread

buffer size and pthread


In the programming question of Homework 2, there are two versions of the shared memory producer-

consumer program (either leave one slot of the buffer empty to indicate an empty buffer or using all slots for
storing data. Write two pthread programs, each for one of the versions. In your code, consider “item” as a
‘char’ type, and the main function creates two threads (producer and consumer). The producer read the text
shown at this URL: “…”, and write them, character
by character, to the buffer (you may first download the file and read from the local file). And the consumer
reads from the buffer and print them to the screen, character by character. Your code’s logic should match
that of the homework code.  

Observation: For each of the buffer sizes (2, 3, 5, 10, 15, 20, 25, and 30), measure number of trips for the
producer to deliver characters to the buffer in each version of the programs. A trip is defined as one or
multiple continuous writes to the buffer without being interrupted by a busy waiting (run into the “do 

nothing” code line due the a full buffer). Insert code into your programs to collect the statistics and report
them in a table.