JR Language Reference

This page provides a short syntactical reference to the JR language and its various constructs for concurrent programming. The meaning of the constructs is not explained in any great detail, we refer to the lecture notes for that.

First of all, JR is an extension of Java. This means that every valid Java program is also a JR program. You can you all the features and libraries of Java when programming in JR. In addition to the features of Java, JR provides a number of language constructs for concurrent programming.

Note that you should not use Java's constructs or libraries for concurrency when programming in JR. Bad things will happen if you do.

Semaphores

JR provides semaphores as follows.

Declaring a semaphore: sem s = 1;
Operations on semaphores: P(s);
V(s);
s.length();

Operations

JR provides operations which is a generalization of message passing and provides several ways of communications.

Declaring an operation: op void channel();
op int fac(int n);

Invoking operations

Assuming we have an operation declared as follows: op int fac(int n);

Asynchronous: send fac(3);
Synchronous (ignoring the result): call fac(3);
fac(3);
Synchronous: int n = fac(3);

Servicing operations

By a method: op int fac(int n) { if (n==0) return 1 else return n * fac(n-1); }
By receive statement(assuming we have declared a variable int a;): receive fac(a);
By input statement: inni int fac(int n) { return 5; }
Examining the number of messages in an operation: fac.length()

Additional constructs in the input statement

Listening to multiple channels: inni void a(int x) { .. }
[] void b(int y, int z) { .. }
Return to the caller early without exiting the input statement: reply;
Forwarding the message to another channel: forward fib(n);
Conditionally accept messages: inni void a(int x) st x%2 == 0 { .. }
Prioritizing the messages within a channel: inni void a(int x) by -x { .. }
Else branch: inni void a(int x) { .. }
[] else { .. }
Last modified: Sunday, 26-Jun-2011 16:26:36 CEST
COMPUTER SCIENCE AND ENGINEERING - Chalmers University of Technology and Göteborg University
SE-412 96 Göteborg, Sweden - Tel: +46 (0)31- 772 1000