Ordered queues. The simplest implementation of an ordered queue between two processes is a distributed array. For example, the producer can write memos into folders thus:
#define QUEUE ......FOLDER_NAME dest;int outpos = 0;dest.S = QUEUE;dest.X[1] = dest.X[2] = 0;...while (1) {... produce item M ...dest.X[0] = outpos++;memo_write(dest,&M,sizeof(M));}
And the consumer can remove them similarly:
mine.X[0] = inpos++;p = memo_get(mine);
Problem: Producer can get arbitrarily far ahead of the consumer.
Ordered and bounded.
Bounded buffer problem: two processes communicate through a bounded buffer, which actually is a bounded FIFO queue. Solution, use the ordered queue and another folder for a semaphore. Resembles the synchronous communication.
Segmented stream of blocks.
Often want to send a linked data structure to another process. Send by recursively walking over the structure sending out each record. At receiver, process the input with a kind of recursive descent algorithm, reading the objects and linking them back together.
This stream of blocks could be sent through an ordered queue, but there is another alternative that does not delay the sender waiting for the receiver to begin receiving, nor the receiver waiting for more blocks from the sender.
Each sender has an output queue, [output_queue, process, position]. The sender writes the data structure into its output queue and then sends the queue name and the beginning and ending positions to the receiver. The receiver can then read and remove the objects at its own convenience.
This page last updated 09/30/97