HINTS ON HOW TO DESIGN THE PROTOCOL
Imagine that copying the packet in and out of the buffer could
take a very long time because messages can be very large.
You must therefore design the protocol so that no thread ever
has to wait unnecessarily for another thread to finish copying a
packet in or out of a buffer.
On the other hand, assume it takes an insignificant amount of
time to check to see if some status flag is true or false or to
change the value of a status flag. Therefore it is not a
problem if your protocol forces threads to wait for each other
to finish checking or changing status flag(s).
IMPORTANT CONCEPTS THAT COULD BE REGULATED BY FLAGS OR WITH
SEMAPHORES:
- Is buffer[x] "full?" In other words does buffer[x] contain a
packet that needs to be copied out, or is buffer[x] empty and
available for a packet to be copied in?
- Is an agent currently at work doing a copy-out operation on buffer[x]?
- How does a thread gain exclusive access to examine and possibly change the
value(s) of status flag(s)?
- How does a thread gain exclusive access to buffer[x] in order
to copy a packet into it, or in order to copy a packet out of
it?
SIMILARITIES WITH OTHER PROBLEMS:
There is a relation here to the Hi Ho problem. First the
user thread copies a packet into a buffer, and then the
agent copies a packet out of the buffer.
There is similarity here to the producer-consumer problem. A
user is similar to a producer and an agent is similar to a
consumer.
STRAGTEGIES FOR WORKING UP TO A SOLUTION TO THE PROBLEM:
Solving some simplified problems may give you insights that help
you to see a solution to the problem assigned.
Here are some simplified variations on the problem:
- Suppose there is one user, two buffers, and one agent.
- Suppose there is one user, two buffers and two agents.
- Suppose there are two users, two buffers, and one agent.