/*
Filename: ProducerConsumer.java
Author: Professor Needham
Course: SI411
A modification of the Chapter 4 Producer/Consumer example
given in the Silberschatz's OS text.
------------------------------------------------------------------

       SI411 Operating Systems Fall AY07
               Java Programming Lab2
         Due 1530, Date: Wednesday, 20 September 2006.

Overview:  This programming lab explores the use of Java threads in
a producer-consumer application.
-----------------------------------------------------------------------

Deliverables: Each TEAM is to turn in ONE copy of the following by the submission
deadline.  BOTH the paper printouts AND the electronic copies discussed below
are required deliverables.

1. A paper printout of all the .java classes you create, modify or use in this
Lab.

2. A paper printout of consumer.txt and anotherconsumer.txt (see below),
and your handdrawn pictures on a paper copy of demoRun.txt (see below).

3. An e-mail with a zip file (change the .zip to .piz so the e-mail won't be 
tagged as a potential virus) named Lastname1Lastname2.piz containing all 
your .java classes and .txt files.


-----------------------------------------------------------------------

Lab Assignment: Working within your assigned lab team (see course web page),
implement the following.  Use good variable naming conventions such
as using Uppercase for the first letter of words for class names, lowercase 
words for variable and method names, with subsequent words capitalized.

Add comments explaining what your source code is doing, especially where you 
modify any instructor provided source code, or create new code on your own as 
described below.


1. The following files are used in this lab:ProducerConsumer.java, Producer.java,
BoundedBuffer.java, and Consumer.java. Compile the supplied source under code
for these files from the UNIX command prompt:

  javac ProducerConsumer.java BoundedBuffer.java Producer.java Consumer.java

               run with:

  java ProducerConsumer

and observe the program as it runs.  Note that the Consumer thread writes the
first 5 dates that it removes from the "server" buffer to a file called
"consumer.txt"

2.  View the file "demoRun.txt" from the course web page.
By hand, draw a separate picture of the contents of the "server" buffer
as it would have looked at each of lines 5, 10, 19, and 22.  For brevity,
show a date such as => Sat Jan 22 02:34:02 EST 1983 as simply => 02:34:02.
If any of the contents of the "server" buffer would not logically be
accessible to a consumer process at that point in the program's run, indicate
this fact on your drawings.

3. Create a new class called AnotherConsumer, it should behave
similarly to Consumer, but it writes the first 5 Dates it
pulls from the "server" buffer to the file "anotherConsumer.txt"
Note that you must create a whole new class, do not just create a
new instance of the existing Consumer class.

4. Modify ProducerConsumer.java as needed to also include an
additional thread called anotherConsumerThread. Run ProducerConsumer
with all three programmer-specified threads (producerThread,
consumerThread, and anotherConsumerThread) in action.  Allow your
program to run until you have 5 dates in consumer.txt and
5 dates in anotherconsumer.txt.  Using the contents of consumer.txt and
anotherconsumer.txt, draw by hand a picture showing
the 10 dates being created sequentially, and then showing to which
file (consumer.txt and anotherconsumer.txt) the date was assigned.

5. If you finish during the lab, you may leave after demo'ing your program 
for your instructor when you have finished. Remember to turn in the deliverables discussed above by the due date.


*/

public class ProducerConsumer {
	public static void main(String args[]) {
		BoundedBuffer server = new BoundedBuffer();

      		// now create the producer and consumer threads
                System.out.println("Creating producerThread");
      		Producer producerThread = new Producer(server);

                System.out.println("Creating consumerThread");
      		Consumer consumerThread = new Consumer(server);

                System.out.println("Starting producerThread");
                producerThread.start();

                System.out.println("Starting consumerThread");
      		consumerThread.start();

	}
}

