Do the following on top of
your Lab 3 work:
1) Remove
the insert task and the three lookup tasks. Also remove
the
progStop
function.
2) Rewrite
the progStart function to spawn one requestHandler task,
one
insertRequest task and one lookupRequest task, with the
lookupRequest task
spawned 200 clock ticks later than the
other two tasks are. Also create two
message queues: insertMsgQ and
lookupMsgQ.
3) The
insertRequest task periodically sends messages to insertMsgQ
requesting
to insert new items to the database.
-- Each time it sends a request,
it sleeps for 15 clock ticks.
-- The request message includes the new item ID and item price.
-- The values of item ID and item
price are set according to the algorithm used
for the insert
task in Lab 3.
4) The lookupRequest task periodically
sends messages to lookupMsgQ
requesting to inquire item prices:
-- Each time it sends a request, it
sleeps for 75 clock ticks.
-- The request message includes the inquired item ID only.
-- The item ID is set according to the
algorithm used for the lookup tasks in
Lab 3.
5) The
requestHandler task keeps checking the two message queues.
-- Each round it checks insertMsgQ first then
lookupMsgQ.
-- If no message is received
from either queue in a round of polling, it sleeps
for 10
clock ticks.
-- When a message from insertMsgQ is received, it inserts the
corresponding
node to the trees.
-- When a message from
lookupMsgQ is received, it searches the trees for the
corresponding node and then display the item price.
6) The
program runs for 20 seconds then it automatically stops, with all trees
displayed and then erased.
On the due day, you need to send me a softcopy of your source code. You
also
need to
give me a demo of your work in the lab.