During the session:
- Make a JAVA program to model a Producers/Consumers system.
There should be a stack which is filled by Producers and emptied by
consumers. Use the class stack from JAVA, with MAX elements. The
producers can fill elements while the stack is not full, whilst the
consumers can take elements whilst it is not empty. Visualize the
contents of the stack while executing the program. For simplicity,
consider only one producer and one consumer at the beginning.
- Make three JAVA programs (one for each condition below)
with four processes which write letters
from the alphabet {a,b,c,d} 100 times, under the following conditions:
- Without requiring any specific order, i.e., without
guarded blocks.
- Writing abcdabcd...
- Letters a and d must be intercalated as letters b and c, but each pair independently, as
in the word adabdadcb.
Make the programs in such a way
that it can be easily generalized (adding a few lines of code) to 10
instead of 4 letters.
|
After the session:
- Make JAVA programs that are modifications of the program 1
done during the session (Each one of the modifications
must be done starting from the initial version of the program (i.e.,
don't do them incrementally!)):
- Producers produce different amount of elements, Consumers
consume different amount of elements.
- Producers produce different types of elements, and
Consumers consume also different types of elements. Then a consumer
must wait until a producer of its type has generated the item he is
waiting for.
- Producer-Consumer nodes: there are some nodes that have
both roles (producer and consumer), and when they cannot consume go to
produce few items and try to consume afterwards.
- [OPTIONAL] : Adapt the BST class presented in the previous
session to allow for concurrent insertions, by using synchronized
methods. Make a program where several threads insert concurrently in a
BST and provide the contents at each insertion.
|