Post by G G
to a separate reply port. Each port may have multiple senders, but
only one receiver.
This restriction is badly stated.
Without saying so explicitly, it is taking the point of view that a port
is actually a message box belonging to the receiver, and that the
definition of a "receiver" is that it is a service which receives
requests, performs some actions, and produces replies.
Of course, multiple clients use the service.
In reality, even under the above assumptions, such a service can be
performed using multiple processes, which all wait for a message from
the same queue. The sender does not know or care which of those
processes services the message.
It would be better to describe the semantics of a port itself without
tying it to a particular intended scenario like multiple client sharing
the same service using a send/receive/reply discipline.
If the communication port has no *inherent* addressing mechanism, then
it is restricted to a single logical receiver and sender.
So that is to say if we can do only:
message = receive(port)
without any addressing arguments about who is sending the message
and who is to receive it, then to the port itself, all senders look
the same and all receivers look the same.
What the book is getting at is the message box model: each task in the
system has its own port from which only it receives. This means that
if we do:
the send operation is *implicitly addressed* by the fact that we really
port = intended_recipient.message_box
Now what is missing is that since we expect a reply to our message like
"your request was done", we have to include our address. If the port
doesn't know about that, we have to encode it in the messaage.
# get the message box of the "intended_recipient" task
service_port = intended_recipient.message_box
# indicate our own message box in the request
message.reply_to_port = THIS_THREAD.message_box
# send the request
# wait for reply no our own message box
reply = receive(THIS_THREAD.message_box)
Then the receiver, the "intended_recipient", can do this:
# receive the request
message = receive(THIS_THREAD.message_box)
# do the request and produce a reply
reply = do_the_operation(message)
# send reply to the port indicated in the request
But this idea that tasks have a message box isn't the only possible use
case for these ports. For instance, a group of tasks could constitute a
service, and then that service entity will have a single message box.
The sender then does:
# get the message box of the foo service:
service_port = foo_service.port
The service has multiple tasks doing this at the same time:
message = receive(foo_service.port)
It's not even the case that the senders have to use their own message
box. The requests could be made using multiple threads on behalf of some
subsystem in which there is a single reply port for all the request
completions. So those threads specify that reply port, instead of their
own private "message box" port.
TXR Programming Lanuage: http://nongnu.org/txr
Music DIY Mailing List: http://www.kylheku.com/diy
ADA MP-1 Mailing List: http://www.kylheku.com/mp1