Background:
Here is a specification for a Demos-like model of interprocess
communication that can be implemented under our example thread manager:
- s = send( dst, buf, len );
- send to dst (of type link) the contents of the buffer
buf (of type void*) with a length in bytes of len (of type int).
Variables of type link may be directly included in the buffer.
This blocks until the message has been delivered and returns the
number of bytes actually copied to the receiver. If dst is an
invalid link
- s = receive( queuetab, number, buf, len );
- receive a message from the indicated queue number (an integer) in the
queue table queuetab (of type queuetable*) into the buffer buf (of type void*)
with a length in bytes of len (of type int).
This blocks until a message has been delivered and
returns the number of bytes actually copied from the sender.
- number = queueselect( queuetab, numbers, len );
- given numbers (of type int*), an array of len (of type int) integers,
each interpreted as a queue number, and given queuetab (of type queurtable*),
block until one of the queues indexed in numbers contains a message, and
return the queue number. If more than one of the queues mentioned in
numbers contains a message, the number returned may refer to any one of
them.
- queuetab = newqueuetable( slots );
- allocate a queue table with a capacity of slots queues (an integer),
returning a pointer to that table in queuetab (of type queuetable*).
All the queues in the table are initially empty.
- link = newlink( queuetab, number );
- return a link allowing sending of messages to the indicated queue number
(an integer) in the indicated queue table.
Note that this set of primitives doesn't require the use of a link table
because we allow links to be stored intermixed with normal variables.
Note also that the queue table is not necessarily implemented as an array
of queues! It is an abstraction which may have additional complexity.
Part A:
If it were not for the queueselect service, there would be many
ways to implement this set of primitives. Therefore, you must begin
your implementation by working out a feasible implementation for queueselect,
using semaphore operations for synchronization, plus whatever other data
structures are required to make it work. Propose a solution.
Part B:
Give the header file that gives the interface specification for this
package. This should conform to the style guidelines referenced from
the class web page, and it need not attempt to hide the implementation of
the data structures from the reader.
Notice:
The complete implementation of these functions will be assigned in
next week's homework.