CSci 4061: Introduction to Operating Systems - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

CSci 4061: Introduction to Operating Systems

Description:

We are going to discuss an implementation of the Producer-Consumer problem in ... CHANNEL and writes them to the respective mailboxes of the consumer threads ... – PowerPoint PPT presentation

Number of Views:111
Avg rating:3.0/5.0
Slides: 12
Provided by: tia64
Category:

less

Transcript and Presenter's Notes

Title: CSci 4061: Introduction to Operating Systems


1
  • CSci 4061 Introduction to Operating Systems
  • Recitation IX
  • 03/31/2008

2
Todays agenda!
  • Download Lab_Ex9.tgz
  • UnTAR it and check if you have a file prodcom.c
  • We are going to discuss an implementation of the
    Producer-Consumer problem in conjunction with
    Assignment IV.
  • All set?

3
Producer-Consumer Problem
  • A classic example of multi-process
    synchronization
  • Also called the Bounded-Buffer Problem
  • Producer pushes an entity into the buffer and the
    Consumer retrieves it
  • But the buffer is bounded?
  • What are the implications?
  • The last slide has references to some good
    discussions on the topic, just in case

4
prodcom.c The program
  • gcc w lpthread prodcom.c
  • ./a.out
  • Produces multiple lines of output!
  • Let us take a look at the code constructs
  • Open the source code in your favourite editor!

5
Assignment IV A Multi-Producer Multi-Consumer
Problem
  • Five producer threads named Red, White, Blue,
    Green and Orange
  • Read from their respective input files named
    red.in, white.in, blue.in, green.in and orange.in
    respectively.
  • Write to a shared buffer called CHANNEL of size
    20 records!
  • Why is the size important? How will you
    synchronize the working of producer threads?

6
Assignment IV A Multi-Producer Multi-Consumer
Problem (Contd.)
  • Another thread called Router pops out the entries
    from the buffer CHANNEL and writes them to the
    respective mailboxes of the consumer threads
  • How does it identify which buffer to write to?
    Colour coding of input!
  • Consumer threads then pick the entries from
    their respective buffers and write to their
    respective output files. Simple!

7
A Picture Speaks Better .
8
Parallels with the Original Problem
  • Similarities
  • Buffer is bounded
  • Thread synchronization required
  • Inter-thread communication
  • Differences
  • An intermediary called Router
  • A producer and its corresponding consumer do not
    use the same buffer
  • Synchronization between producers

9
Issues!
  • Synchronization of the producers
  • The working of Router
  • Synchronization of the consumer threads
  • Most importantly, the size of the input files is
    not bounded!

10
Reference
  • https//computing.llnl.gov/tutorials/pthreads/
  • http//en.wikipedia.org/wiki/Producer-consumer_pro
    blem
  • http//www.dcs.ed.ac.uk/home/adamd/essays/ex1.html
  • Remember, no reference is given for the heck of
    it!

11
Questions/ Criticisms?
  • Anything is welcome!
Write a Comment
User Comments (0)
About PowerShow.com