CSCI 152: Operating Systems Programming

Laboratory Assignment 2

ASSIGNMENT DUE: see calendar on the web

Assignment Background:

Lab 2 is going to be written in C and is going to make use of posix threads, semaphores and mutexes.  So when you find people to be in a group with you should keep this in mind.  I'm going to recommend doing this assignment on tiglon (Solaris).  I know it will also be possible to do it on Linux, and it probably can be done on FreeBSD and MacOS X but I do not know if MS Windows has the right libraries (maybe it could be done with cygwin?).  So I don't care what platform you do it on but if your platform does not have pthreads you can not do it on that platform.  [Also, I haven't done any testing on steroid which is HP/UX].

Using the man pages:

The man pages will be your primary reference for pthreads, semaphores and mutexes.

man is a unix command (short for "manual").
 
To view a man page you type "man" followed by the thing you want to see the manual page for.
 
Commands inside man:
  <enter> - move down a line
  <space-bar> - move down a pageful of text
  q - quit
  b - back a pageful of text
 
Command to help you find man pages:
  man -k <keyword>

You can view a man page from a particular section by using the -s option:
  man -s3c sleep

Man pages are divided up into sections:
 
Section - Contents
--------------------------------------
 1 - User Commands
 2 - System Calls
 3 - C library functions
 4 - Devices and network interfaces
 5 - File formats
 6 - Games and Demos
 7 - Environments, tables, and troff macros
 8 - System maintenance
  
Try the following commands and read the documentation:
-------------------------------------
man pthread_create
man semaphore
man mutex
man pthread_join
man sem_init
man sem_wait
man sem_trywait
man sem_post
man rand
man -s3c sleep
man -s3c printf

Also check out the EXAMPLE CODE

C reference material:

Since many students in this class come from a background of mainly C++, Java or Perl (myself included) you will probably also need a C programming reference.  A great reference book on C programming is, "The C Programming Language" see http://cm.bell-labs.com/cm/cs/cbook/. Unfortunately, this is not a free book.  I think it is great though and I really recommend purchasing it (other C reference books might be just as good).  Barnes and Noble here in town had a few copies last time I was there.  There is a slight discount at bookpool, see http://www.bookpool.com/.x/ozdbhder1i/sm/0131103628.  Please note that this book is only a reference to the C programming language and does not contain any info on posix threads, semaphores, and mutexes.  It documents stuff like input and output structs, pointers, <stdlib.h> and so on... (This book could possibly be useful in other courses like CSCI250, CSCI272, CSCI372 or any other course involving the C language).

If you have never used C before don't freak out too much, it is just like C++ without the classes and some other stuff.  Instead of cout's you use printf's and instead of methods you have functions and instead of using g++ you use gcc.  You will have to do some reading though.

The reasons for restricting this assignment to C:

Lab Assignment 3:

Just so you know lab assignment 3 is likely going to involve modifying lab 2 in some way to add some kind of functionality.  Like turning it into a network program or something.

Assignment Description:

Initially I was going to assign the dining philosophers problem.  A friend pointed out there are only about a million solutions to the dining philosophers problem posted on the web.  So this is something more original.

This program solves a producer-consumer problem.   The "producers" are going to generate print jobs and the "consumers" are going to be printers which print print jobs.  A print job will have an ID, page length, and a field holding the producer ID which created it.  Each producer thread will create print jobs randomly and then put them into a queue of limited size.  Consumers threads will remove "print jobs" from the queue and "print" them by sending output to the screen.

This program will have a main that creates producer threads and consumer threads.  Each producer thead can be thought of as a person that generates print jobs and each consumer thread can be thought of as a printer.  

 Each person (producer) does the following:Each printer (consumer) does the following:
You should be able to turn off all sleeping using a debug level feature like that used in program 1.

Problems to Avoid in Producer/Consumer:


Goals:

Learn about operating system fundamentals, including history, process and thread management, concurrency with semaphores and monitors, deadlocks, storage management, file systems, I/O, and distributed systems.

Objectives:

Expected Outcome: