Lab 4: RingBuffer

Introduction

In this lab you'll be using pthreads to implement a producer/consumer model with a shared buffer. There will be two threads: a producer and a consumer. The producer will read information from standard input and place it into a ring buffer. The consumer will extract information from the buffer.

Starter Code and Instructions

Starter code

The starter code for this lab is already available on the server in the directory /cs/cs105/labs/lab4-ringbuf. The first step is to get your own copy of the code to work on. After logging into wilkes, run the following commands:

mkdir -p ~/cs105
cd ~/cs105
cp -ai /cs/cs105/labs/lab4-ringbuf .
cd lab4-ringbuf

Recall that this will cd into your cs105 working directory, copy the starter code into a new directory called lab4-ringbuf and cd into that directory.

If you run ls, you'll see that there are two C files:

There's also a Makefile to build the code, and some test input and output files you can use to check your work.

PThreads Synchronization Demo: The Party Room

We've provided a small demo program called party.c that simulates a party in a room with limited capacity. Guests arrive, wait if the room is full, dance for a while, and leave. party is short, it compiles, it runs, and it uses every pthreads pattern you'll need for the ring-buffer lab. See this description for more.

Ring Buffer handout

When you're ready to start implementing your Ring Buffer, here is the lab handout.

Due Date and Submission

Due: Monday October 26th, 11:59pm -- note the atypical due date!!

As described in the writeup, you should submit ringbuf.c using the following command:

cs105submit -a 04 ringbuf.c