DS 7 - Semaphores
 All Data Structures Files Functions Variables Macros Pages
CS 241 Discussion Section 7 - Semaphores
CS 241 - Semaphores

Introduction

The proposed problem is a classical producer-consumer scheme in which there is just 1 producer and one consumer manipulating the bytes in a shared circular buffer. In particular, the shared buffer will be a an array of chars in which the producer writes one byte at a time getting it from a default string. We are going to use sem_wait and sem_post as primitives to provide semaphore functionality.

Tasks

What has to be done is:

  • Complete the initialization of the variables
  • Implement the Producer
  • Implement the Consumer
That's all.

Compile and Run

To compile these programs, run:
make clean
make
To run your own implementation (ds7.c):
./prodcons

Extensions

We will also discuss two extensions of this work:

  • A periodical print of the status of the shared buffer
  • A n-prodicers, m-consumers version of the same problem