back to Parallel Programming Languages
Joyce is a parallel programming language created by Brinch Hansen. Joyce derives its syntax from Pascal, and its support for concurrency derives from the rendezvous semantics of CSP. A Joyce program consists of procedures that define agents. An unbounded number of agents can be created by recursively spawning them.
A parallel program has a set of channels through which an agent can communicate with other agents. Only when an agent is in a state where it is ready to receive a message from a channel, and another is in a state where it is ready to send a message through the channel does the message gets sent (this is sometimes called a rendezvous).
Although many agents can use a channel, only two can rendezvous on that channel at a time. When there are several agents who are ready to send or receive a message through a single channel, the language semantics defines that a sender/receiver pair be non-deterministically chosen to rendezvous.
Here is a code example for sorting:1
agent sort(inp, out)
x, y: integer;
more := true;
| inp?eos ->
more := false;
while more do
if x > y then
succ!int(x); x := y
| inp?eos ->
more := false;
The code above describes a sort agent that takes in two channels, inp and out. We assume that the input is a list of integers, terminated by the eos (end of srtream) symbol. At the start of the program, the agent polls the input channel to accept an integer, assigining it to the variable x. When an integer is obtained from the stream, sort is recursively called, which spawns a new agent. The new agent is handed the same output channel as the parent agent, but is given a new channel named succ as the input stream.
The second part of the program polls the input stream for integers until the eos symbol is received. If the new value y is smaller than x, then x is sent to the succ channel, otherwise, y is sent to the channel. This means that each agent stores the minimum element in the stream it receives, and passes on the rest to the next agent. Once the eos is received, the stored integer is output to the channel.
From the code above, it is easy to reason out that the output indeed will be in sorted order, and that this algorithm takes O(2n) time. In fact, the main attraction for using a CSP based language is that CSP has a very strong mathematical foundation as a basis for the analysis of concurrent algorithms.
Several languages such as occam have direct support for CSP semantics, while libraries that support CSP have been written for other languages, like Java. Ada has support for the rendezvous semantics of CSP using its guarded command statements.
1 The code is taken directly from the reference, only the formatting was changed, for better readability.
Per Brinch Hansen, Joyce -- A Programming Language, 1987, in The Search for Simplicity Essays in Parallel Programming, IEEE Computer Society, 1996, pp. 277 - 305.