Communication in C-with-Ease occurs through objects called contexts. Contexts are first class variables and may be passed as parameters, assigned to one another and stored in structures. Communication is asyncronous - a process writing an object into a context does not wait until that object has been read.
There are four different types of context, each with different properties. A stream context guarantees that the order of object placement matches the order of retrieval (it is a distributed FIFO queue). A bag context relaxes the ordering constraint on stream contexts - the order of object removal is arbitrary. Both of these contexts may contain an unlimited number of objects.
A singleton context may contain at most a single object. If a second object is placed into the context it replaces the existing object.
The fourth type of context is a reply context. This provides remote procedure call semantics. xxx refer to rpc reference: Nelson, B.J. Remote Procedure Call, Doctoral Dissertation, Dept CS Report CMU-CS-81-119, CMU, May 1981.
Context variables may be assigned to one another, passed through contexts, passed as parameters and used in context operations.
This C-with-Ease implementation has a number of limitations regarding the declaration and use of context variables and types. One cannot typedef a context type, hencetypedef @share bag will not work. Also, declaring a new context variable with the same name but a different type will confuse the compiler, even if they are in different scopes.Arrays of contexts, pointers to contexts and context elements of structures and unions are legal however.
C++ -with-Ease differences:The context types must be templated on argument type and do not have the same limitations as in C-with-Ease .
Contexts must be initialized before they are used. This is acheived with the @init statement. @init changes the value of a context variable, so it should be called before passing the variable to spawned processes.
@init may be called multiple times for a single context variable, however, each time the variable will refer to a separate new context.
C++ -with-Ease differences:Initialization is done using the C++ constructor mechanism. Thus the @init statement is unnecessary in C++ -with-Ease .
Context variables are really handles on much larger structures that reside on the processor where the context was initialized. Interactions with the context will interact with that processor.
The location of contexts may be influenced with the @own statement, which directs the runtime system to move the context data nearer to the current processor. This may improve performance by reducing the number of inter-process messages required for context operations.
xxx Discuss migration mechanisms - probably elsewhere.
It is often best to migrate the context data to the process that will be the recipient of most of the data sent through that context.An implementation need not take any action in response to a migration directive.
Contexts die when the process which created them terminates. If a process interacts with a dead context then that process may be killed by the system.
Currently, the only interaction with dead contexts which will not cause the termination of the process is a write from another processor.
Note that a context may outlive the context variable that it was created with and there may be other (copied) handles on the context.
Ease provides four operations on bag, stream and singleton contexts. Reply contexts operations will be described shortly.
The operators are designed to be symmetrical. @write and @read copy data to and from a context, @put and @get move data to and from a context. Once data has been @put it no longer belongs to the caller and should not be referenced.
Only a single type of data may be passed though a particular context. This data is binary copied, so pointers or variable sized structures are unable to be passed.
The @get! and @put! forms allow for exchange of data by reference. The pointer passed to @put! is reset to 0 (since the current process no longer "owns" the data) and the system takes responsibility for freeing the data. The pointer passed must therefore be allocated with malloc. @put! obtains a pointer to the data it receives, the freeing of this data is the responsibility of the caller.
Combining different forms of get and put is legal: the system takes care of allocation and deallocation as necessary. The user may @put! data and retreive it with @get.
@write should really allow passing of arbirary expressions, but doesn't due to limitations in varargs handling on different architectures and a portable implementation is sought.Data that is @put may still be used by the caller in this implemenation (the same is not true for @put!). There is no type checking, so using different types for different operations on the same context will not be detected except by indirect run time errors.
C++ -with-Ease differences:Context operations are type safe, and variable sized structures may be safely passed through the use of marshalling functions.
Reply contexts provide call-reply semantics, that is, they allow the process that receives data to send a reply to the process that sent the data. This cannot be easily acheived using the other context types.
The call
A resource statment
The "!" forms behave similarly to @get! and @put!.
The non-pointer call value and the reply value should really be general expressions (as should @write).
C++ -with-Ease differences:The syntax of reply is different, becoming similar to @put.
The select statement provides a construct to receive data from one of a number of contexts which may or may not be ready to supply data. It also provides a mechanism for testing whether or not a context contains data.
The select construct will only consider a select_clause if it has no select_guard or if the guard expression is true. It then waits until one of the clauses can be satisfied and executes the code associated with that clause (after performing the corresponding get, read or resource statement).
If there is an @else clause with no @after, then if data is not immediately available that clause will be executed. If there is an @else @after clause, then the process will wait for data for at least the time given by the corresponding expr (a double value in seconds).
If there are multiple @else clauses or multiple select clauses for the same context then selection between them is arbitrary. The programmer should not rely upon the selection following any particular rules.
An empty select or one whose clauses all have false guards successfully completes immediately.
Note that while the time before an @else @after clause will execute is at least a particular value, there is no upper limit on the time.Next: An example program Up: C-with-Ease language definition Previous: Process controlWhen dealing with contexts on remote processors the select construct can generate a large number of messages, it does however, do no inter-process communication if the operation can be satisfied locally.