COSC 625 Real Time Processing -- In CLASS LAB WORK -- Fall 2010
22 September 2010 - Today's purpose is educational! Those of you who are
good programmers in Java will assist those of you who are not.
Work in a paired programming style,
where the first programmer is the more experienced programmer. After 10 minutes, switch with
the navigator.
- Starting from
Process2.java
and HelloWorld1.java
, make code so that each
task outputs the entire String without interleaving from any other output task.
DO NOT just copy and paste any already obtained solution from before today's paired programming.
- This is a basic producer/consumer problem.
Create a circular queue that comprises an int
array size 1024, a head
index and a tail index. Access to this array is controlled by a binary semaphore.
Create two tasks:Producer and Consumer. Producer runs a for
loop with 100 iterations. Each iteration, Producer randomly
generates an int
and stores the int
in the queue.
At the end
of Producer's iterations, Producer outputs an "Execution complete" or similar.
Consumer has two (or three) counters: even counter (optional odd counter) and total counter.
Consumer runs a for
loop with 5 iterations. Each iteration,
Consumer accesses
the queue. If there is data available in the queue, Consumer will delete a single datum, determine
if the datum is even or odd, increment
the even or odd counter as appropriate, and increment
a total count. When Consumer completes its iterations, it outputs the result of its counts.
When class time is over, copy your best code to your own space and work on it on your own or with friends. Make sure you
understand your solution.
Last changed: