Previous Up Next

3.5  Processes

process ::=  0  
  process &  process  
  expr  expr  
  expr ;  process  
  reply [ expr ] to  lowercase-ident  
  if expr then  process  [ else process ]  
  match expr with  { | ocaml-pattern  [when expr->  process }+  
  let [ rec ] ocaml-let-binding  { and ocaml-let-binding } in  process  
  for lowercase-ident =  expr  ( to ∣  downto ) expr do  process done  
  ( process )  
  begin process end  
   join-definition in  process   
 

The class of processes is the main syntactical extension of JoCaml with respect to Objective Caml. Processes have no result. By convention, we say that processes are executed, while expressions are evaluated to some result. Moreover, expressions may fail to produce a result and instead raise an exception. The matching concept for processes is abnormal termination. When a process terminates abnormally, the JoCaml runtime system issues a warning message.

3.5.1  Basic processes

Those are directly inspired from the join-calculus.

Inert process

The simplest process is 0 (concrete syntax is the digit 0). This process does nothing.

Grouping

The processes ( process ) and begin process end execute as process does. Both constructs are semantically equivalent, using one construct or the other is a matter of style.

Asynchronous send

Asynchronous send expr1  expr2 evaluates expr1 to an asynchronous channel and expr2 to a value. Then, the value is sent on the channel. Notice that the syntax is the one of function application, but in process context. Although the syntax is quite general, common usage is simpler. Most often, expr1 is a channel name, while expr2 is a tuple of expressions : lowercase-ident (  expr1,  expr2,...,  exprk ).

Concurrent execution

The operator & is the parallel composition. Executing process1 &  process2 amounts to executing process1 and process2 concurrently.

Reply to synchronous sends

The process reply expr to  lowercase-ident sends the value of expr as a reply on the synchronous channel lowercase-ident, which must be the name of a synchronous channel. The reply construct is of course to be used while defining the receiving side of a synchronous channel. On the other side, sending a message on a synchronous channel is very similar to calling a function, and the replied expr is like the value returned by a function call.

There are severe linearity constraints over the usage of reply. Linearity constraints here mean that the compiler enforces that exactly one reply to a given channel is allowed. For instance, in process1 & process2, the processes process1 and process2 must reply to disjoint sets of channels; while, in if expr then process1 else process2, the processes process1 and process2 must reply to the same channels.

3.5.2  Composed processes

Composed processes are the equivalent of some of the control structures of Objective Caml, but at the process level.

Sequence

The process expr ;  process evaluates expr first, then it executes process. The expression must be of unit type (by contrast with Objective Caml). Notice that the item before the semicolon ; is an expression, not a process — a process there would be meaningless.

Operator & binds tighter than operator ;. As a result, expr ; process1 & process2 is legal syntax and expr evaluates before both process1 and process2 execute. Moreover, process1 & expr ; process2 is illegal syntax.

Conditional

Executing the process if expr then  process1 else  process2 executes process1 if expr evaluates to the boolean true, and process2 if expr1 evaluates to the boolean false.

The else process2 part can be omitted, in which case it defaults to else 0.

Pattern matching and let definitions in processes

Those two constructs are like their (Objective Caml) expression counterpart, except that they are processes and that they introduce bindings of names to values over processes in place of expressions.

Concurrent for loop

The process equivalent of the traditional for loop. Iterations are executed concurrently.

Local definition of channels in processes

Local definition of channels by a join-definition is possible inside processes.


Previous Up Next