Guardian Programmer's Guide

Table Of Contents
Communicating With Processes
Guardian Programmer’s Guide 421922-014
6 - 17
Handling Multiple Messages Concurrently
Handling Multiple Messages Concurrently
So far, you have seen how a server processes requests one at a time as it reads them
from the $RECEIVE file. However, in some applications, it could happen that for the
server to complete a request, it must wait for events outside the server process to
finish. Other requests might have to wait a long time for the server to become
available. By handling multiple requests concurrently, the server is able to process
requests while waiting for longer-running requests to finish.
This subsection describes how the server can read several requests from $RECEIVE
and then process and reply to them in any order. To do so, the server typically
executes the following sequence:
1. Open $RECEIVE with a receive depth equal to the maximum number of requests
to this process that you want to be able to process concurrently.
2. Read requests from $RECEIVE. The file system assigns a tag value to each
message and keeps a list of all messages that you have read from $RECEIVE but
not yet replied to.
3. Process these requests in any order. This gives the server the flexibility of
assigning priority to requests or processing requests concurrently.
4. Reply to each message after processing. The file system removes the message
from the list of messages that have not been replied to.
The following paragraphs describe how the server process performs these functions,
including how to ensure, when you send a reply, that the reply goes to the process that
issued the corresponding request.
Opening $RECEIVE to Allow Concurrent Message Processing
To open the $RECEIVE file and enable concurrent message processing, you need to
set the receive-depth parameter equal to the maximum number of messages that
your server program will queue before replying. The length of this list is an application
design issue.
The following example sets the receive depth to 4:
FILE^NAME ':=' "$RECEIVE";
LENGTH := 8;
RECV^DEPTH := 4;
ERROR := FILE_OPEN_(FILE^NAME:LENGTH,
RECV^NUM,
!access!,
!exclusion!,
!nowait^depth!,
RECV^DEPTH);
IF ERROR <> 0 THEN ...