Do the following on top of
your Lab 2 work:
1) Implement a progStart function, which spawns one
insert task and three
lookup tasks, with the
lookup tasks spawned 200 clock ticks later than
the insert task is.
2) The
insert task keeps on inserting new nodes to the trees.
-- Each time it inserts a new node,
it sleeps for 10 clock ticks.
-- The key value of a new node is
random number generated according to the
following recursion algorithm:
yk+1 = (a * yk + b) % m
keyValue = 1000 + (yk+1 % n)
where a = 56789, b = 12345, y0 = 12345, m = 32768, n =
8999.
-- All new item price is 9.99.
-- Based on the above algorithm, y1
= 1190, y2 = 23639, ... and the first item is
(391, 9.99),
the second item (365, 9.99), ...
3) The three lookup tasks inquire item prices
periodically. The period of the first
task is 90 ticks, the second one 120
ticks and the third one 150 ticks. Each task
does the inquiry independently on
items according to the order that they are
generated by the insert task.
In other words, each lookup task follows the same
algorithm as shown in 2) to decide
the item IDs to inquire. When an item is
inquired, display:
-- the lookup task ID,
-- the item ID and item price.
4) Use
semaphores to control access to the trees. Here are the polices:
-- The lookup tasks can access the trees simultaneously.
-- The insert task
always requires exclusive access.
-- The first lookup task
has to compete for the access with the insert task.
-- As long as a lookup
task holds the trees, another lookup task will get
access
to the trees automatically regardless of whether the insert task
is
is
waiting to access the trees or not.