Download Heaps and Hops

Transcript
Chapter 2. A Model of Copyless Message Passing
k to enqueue the pair (a, v) in the buffer of ε′ , resulting in α ⋅ (a, v) (where ⋅ is
the concatenation operation over words). The command faults if any of the lookups
fails. Note that sending never blocks and, provided that appropriate resources are
held, always succeeds.
• The case of receiving is more involved, since it may only be performed inside an
external choice block.1 The reduction rule selects an available message in one of the
endpoints’ buffers that is awaited by one of the receives. In other words, it selects
a message (ai , v) such that xi = receive(ai ,Ei ): pi is one of the guarded processes of the external choice. If it finds such a pair, it pops it from the corresponding
buffer, and stores the value of the message in xi . If not, there are two possibilities:
either the buffers of all the endpoints mentioned are all empty, in which case the receive blocks, or the pair at the top of one of the endpoints’ buffers is an unexpected
one. The latter case produces a MsgError error, even when other branches could
execute successfully.
Finally, if any of the xj is absent from the stack, or if the expressions cannot be
evaluated in the stack, or if they do not all correspond to allocated endpoint locations,
the command faults and results in OwnError.
The semantics of programming constructs is given Figure 2.6. We write freevar (p) for
the set of free variables of p, which is defined as usual by structural induction on p as the
set of variables x that appear in p outside of the scope of a local x in p construct.
For simplicity, the local construct is treated as a statically scoped allocation and deallocation of a fresh variable on the stack. For this purpose, a delete statement is appended
at the end of the program, that deallocates the local variable. Since it only occurs in such
instances, the variable will always be allocated when delete is called, hence we need not
specify it as a requirement in the semantics. The delete command is not part of the programming language (in particular, it cannot be used by the programmer): it is only an artifact
of the semantics.
The semantics of a parallel composition p1 ∥ p2 is all the possible interleavings of the
actions of p1 and p2 , possibly resulting in a fault if there is a race between the two programs.
The purpose of the predicate norace(p1 , p2 , σ) is to detect such races: it checks if there
is an immediate race between p1 and p2 , that is if p1 and p2 are both about to access to
the same resource, and one of them is trying to write to it. Here a resource may be a stack
variable, a memory location or an endpoint of a channel.
Given a program p and a state σ , we define the sets iw (p, σ) and ir (p, σ) of resources
that are respectively immediately written to and read by p in the state σ . Immediately means
that said resources will be accessed by the program at the very next step of its execution
according to the operational semantics. For instance, x = E ; p immediately writes to x
and to x only regardless of what p is, while any program of the form p1 + p2 does not
1
The way it is performed here is unfortunately not compositional, in that we describe only the reduction of all
of its branches at the same time. In particular, we lack a rule that would describe the behaviour of g1 ◻ g2
solely in terms of the behaviours of g1 and g2 considered independently. A modular description is in fact
also possible, but would not be simpler, so we use the non-modular one in this thesis.
39