Newsgroups: comp.sys.transputer,comp.lang.misc
From: andyr@wizzy.com (Andy Rabagliati)
Subject: Re: ALTs and PRI ALTs 
Organization: W.Z.I.
Date: Fri, 29 Apr 1994 06:28:52 GMT
Message-ID: <Cp0Co5.E37@wizzy.com>

[ crossposted to comp.lang.misc ]

>Hi Andy,
>

>I am a recent owner of a couple of transputers. Currently I am writing
>a compiler for my transputers so that I can understand the underlying
>assembler commands. The only problem I am encountering is determining
>the difference between ALTs and PRI ALTs in assembler.

There is none. As you surmised, it is just an code ordering issue.

the PRI in PRI ALT is a very weak form of priority.

What it says is that if more than one guard is ready WHEN THE ALT IS
ENCOUNTERED, the one first in the PRI ALT is selected.

In particular, it DOES NOT do the following :-

     Hmmm - a low priority guard is ready - maybe I will wait around a
     bit and see if a higher one becomes ready soon, and select that
     one instead.

Repeat - it does NOT do this. Somehow many people erroneously think it
does, or do not consider it deeply enough to realise that it could
not.  Similarly, a PRI ALT has no effect on the priority of the
processes communicating with it.

>  The reason why I ask this is because my tutorial book says never to
>use TRUE & SKIP in an ALT statement.

TRUE & SKIP goes against all the reasons for having ALT in the first
place. It implements a busy poll, something the ALT construct was
expressly designed to circumvent.

That said, there are a few (very few) places where TRUE & SKIP can be
useful. One example is :-

	Continue calculating prime numbers until I press a key.

This requires PRI ALT with TRUE & SKIP.

TRUE & SKIP *always* requires a PRI in the PRI ALT.

These problems are rare in real applications.  If you have a problem
that you think needs TRUE & SKIP, look very carefully at it. I mightily
distrust code that contains it.

A boolean guard & SKIP is something I use a lot - just not TRUE as the
boolean guard.

>The reason they give is that the Occam compiler generates the code in
>reverse so that the TRUE & SKIP becomes the first channel guard. What
>if I reverse the compilation and make TRUE & SKIP the last channel? Is
>this OK?

That is all an occam PRI ALT does. The non-PRI case is (justified)
perversity on the part of compiler writers. I see it as making it a
problem sooner rather than later - possibly showing up a bug in your
code.

ALT is a very powerful, and unique, concept. Most of my parallel code
turns out to be processes consisting of ALT constructs wrapped up in
WHILE loops.

>   I have been following the newsgroup for the past few months.
>It seems to me that you are very knowledgable in transputers and
>occam.

Thank you. I consult in parallel processing.

Cheers,     Andy.

--
To see the world in a grain of sand,        Andy Rabagliati   andyr@wizzy.com
and heaven in a wild flower,                                W.Z.I. Consulting
Hold infinity in the palm of your hand,
and eternity in an hour.	-- William Blake

