Newsgroups: comp.sys.transputer
From: jan@neuroinformatik.ruhr-uni-bochum.de (Jan Vorbrueggen)
Subject: Re: The "buffer-copying problem" in OCCAM and CSP
Organization: Institut fuer Neuroinformatik, Ruhr-Universitaet Bochum, Germany
Date: 08 Apr 94 12:03:53 GMT
Message-ID: <JAN.94Apr8130353@thalia.neuroinformatik.ruhr-uni-bochum.de>

Good question. I had a similar problem some time ago, writing software for a
frame grabber that can't loose interrupts (VSYNC connected to event-in), while
it wants to be able to tell some other process that is processing a previously
acquired frame that a new one is ready. If the processing process isn't ready,
I might possibly loose interrupts, as the interrupt process could be waiting
too long. Solution: In the interrupt process, write:

PRI ALT
  from.processing ? are-you-ready ... tell processing new frame is ready TRUE
  & SKIP ... increment the lost-a-frame counter and continue

This was the first time, after using occam for five or so years, that I found
a use for TRUE & SKIP as a guard!

In your case, you could have a buffer process containing a number of buffers
(determined by the average relative production/consumption rates of your
processes and tolerable loss; see a textbook on queueing theory) with
something like:

PRI ALT
  NOT full & from.producer ? next.data.ready ... buffer one more packet of
  data NOT empty & from.consumer ? I'll.take.some.more ... give one buffer of
  data to consumer TRUE & from.producer ? next.data.ready ... relieve producer
  of data and discard, note loss of data

The boolean variables full and empty are manipulated canonically. Of course,
if your producer generates more data, on average, than your consumer can take,
you're out of luck - loss of data will occur, but such is life :-).

Regarding the copying problem - I think that in this case, there's just not
much choice than to violate the letter of occam's aliasing rules in order to
obtain a performance gain. Instead of sending buffers, use indices into a
buffer array. You just have to make sure that these indices are passed around
atomically as access tokens for that buffer segment, then all should be well.
(You could have a seperate process for allocation/deallocation of such buffer
segments.) 

	Jan

