Reactive Programming considers software systems whose behaviors
basically consist in
reacting to activations. These systems
are often called
reactive systems. System reactions, also
called
instants, can take various forms, for example sequences
of successive phases, or oscillations eventually leading to
stabilization. Reactive Programming put the focus on the
semantics and the
programming of such systems.
More precisely:
- The considered systems are made of concurrent
components running in parallel. In the reactive approach, components
share the same instants which thus define a kind of global logical
clock: components synchronize at each end of instant and a
new instant can only take place when all components have
finished their execution for the current instant.
- The possibility to dynamically create and run new
components during execution eases the programming task, as it does not
impose a system to have a static maximum number of running components.
- Concurrent components can communicate and synchronize using
broadcast events. Like in radio transmissions, all components
instantaneously receive the same information. Indeed, no receptor can
miss a generated event and reception occurs in the instant of
generation.
- Decomposition of reactions into micro-steps opens the
way to the programming of systems with special instants (for example
made out of phases or of oscillations).
The project, previously called RC project, has started in 1988.
From then, several programming models and languages have been
designed and implemented:
- The basic model of reactive programming is implemented in
Reactive-C. Reactive-C is actually a preprocessor which
introduces instants in C.
- Dataflow systems made of concurrent processes communicating by
messages are considered in NRP (Nets of Reactive Processes).
This model is actually an example of a reactive formalism which is
not based on broadcast events.
- The synchronous approach, from which reactive
programming is issued, considers, as opposite to reactive programming,
that instants take no time. A variant of the Esterel synchronous
programming language, called SL, has been defined and implemented
with Reactive-C.
- Mixing the reactive approach with objects was the goal of the
ROM model (Reactive Object Model). In this model, objects
run reactive behaviors and communicate by method calls which
are processed at the instant they are issued. The extension to
distribution of the model, called DROM, basically introduces the
notion of a synchronized area in which all reactive objects
share the same logical clock, while distinct synchronized areas run
asynchronously.
- Graphical reactive programming is provided by Icobjs
systems. An icobj has a icon part and a behavior part. In
Icobjs programming, the user does not write code but instead
combines icons at screen to create new icobjs.
- Reactive Scripts offers the possibility to use reactive
programing in an interpretative context, getting thus a complete
flexibility and dynamicity.
- Reactive programming in Java is possible using the two sets of
Java classes SugarCubes and Junior. These formalisms define
reactive instructions as Java objects run by reactive
machines. Moreover, REJO is a programming language which extends
Java for reactive programming. It is used to program intelligent
reactive agents in the dedicated ROS platform.
- Thread-based reactive programming is at the basis of the
FairThreads API. Variants of it are implemented in Java, Scheme,
and C. The LOFT language for reactive concurrent programming in C
is based on FairThreads. It allows users to decompose systems in
synchronized areas and to mix preemptive and cooperative threads.
The first generation of software developped in the project had
Reactive-C as basis; it includes
NRP,
SL,
ROM,
Reactive Scripts over the graphical Tcl/Tk toolkit, and an
Icobjs
system implemented with reactive scripts. The second generation of
sofware is basically based on Java; it includes three versions of
SugarCubes,
Junior,
REJO, and a new
Icobjs
system. Recently,
FairThreads and
LOFT propose a thread-based
approach to reactive programming.
All software developed in the project is open source and
is available on the Internet.
At the beginning, the reactive programming group has received support
from France Telecom-R&D.
The rest of the page gives more details on the various languages
and models considered in the project.
The basic idea of
Reactive-C was to propose a programming style
close to C, in which program behaviors are defined in terms of
reactions to activations.
Reactive-C programs can react
differently when activated for the first time, for the second time,
and so on. Thus a new dimension appears for the programmer: the
logical time induced by the sequence of activations, each pair of
activation/reaction defining one instant.
The present Reactive-C compiler is the rcc version 3 compiler. It works as a pre-processor of C, and is
about 2500 lines of ansi-C. It runs on several Unix platforms (mainly
Sun and Linux), and also on DOS/PC.
Actually, Reactive-C appeared rapidly as being a kind of reactive assembly language that could be used to implement higher
level formalisms based on the notion of an instant.
Nets of Reactive Processes
|
The first formalism implemented in
Reactive-C is
NRP (
Nets of Reactive Processes). In this
formalism, programs are made of reactive processes executed in
parallel and communicating through unbounded first-in/first-out files
called
channels.
Reactive processes are sequential reactive programs which can
put messages in their output channels, and get messages from
their input channels. The key point is that a process which tries to
get a message from an empty channel does not remain stuck forever on
the channel: reactive processes can test for channel
emptyness. Because all processes share the same notion of an instant,
nets of reactive processes are deterministic.
The NRP model is actually an extension of the Kahn model,
introduced in 1974, which allows processes to test channels for
emptyness, while preserving determinism. The test for channel
emptyness gives NRP a more expressive power than Kahn's
networks. For example, it becomes possible to reset a process when it
receives a message on a priority channel, which was not possible in
Kahn's model.
A
first implementation of Nets
of reactive processes exists in
Reactive-C;
a second implementation exists
in Java using
SugarCubes.
The
SL language is a member of the family of
synchronous languages in which reactions are instantaneous. The syntax
is close to
Esterel, but in
SL hypotheses about signal
presence/absence are disallowed. One decides that a signal is absent
during an instant only at the end of this instant, so, reaction to the
absence is delayed to the next instant.
Sources of causal circularities (the so-called causality
cycles) are avoided, while the main features of the synchronous
approach still remain: the expressive simplicity and power of the
parallel instruction, the ease of specification and debugging for
deterministic programs, and the power and modularity of event
broadcasting. However, "strong" preemption is not possible in SL,
which only allows the "weak" one.
Forbidding immediate reactions to signal absences simplifies the
implementation to a large extent (the existing
implementation is less than 1000 lines of Reactive-C). In
addition to directly execute programs, the implementation can also
produce explicit automata by symbolic evaluation.
The RLib library provides primitives to program event-driven
systems made of reactive agents. The basic model of RLib is called
POR.
RLib is written in Reactive-C and was developed by a company
called Soft Mountain. Parts of the Process Control tool PROTOP/IX of
Modcomp/AEG have been written in RLib. PROTOP/IX has been used to
pilot several cement factories of the Lafarge company.
The
Reactive Object Model (
ROM) merges an
object approach with the notion of a global instant. In this model,
methods can be invoked using instantaneous non-blocking send orders
which are immediately processed (that is, processed during the current
instant). Moreover, a method cannot execute more than once at each
instant. The
semantics of ROM has been
studied in cooperation with
Cosimo Laneve from Bologna University
(Italy).
The extension of ROM to distribution is called DROM. In
DROM, systems are decomposed into reactive areas where agents
communicate inside their area by instantaneous orders, and between
distinct areas by usual unbounded delay orders.
A prototype language for ROM has been implemented in
Reactive-C, as a set of macros and a library. An implementation of
DROM in Java, called Rhum, has been developped by
Laurent Hazard at France Telecom R&D. It is based on Junior for
the reactive part and on Jonathan, an open source ORB written in Java, for distribution
aspects.
Reactive Scripts are programs
intended to be run by reactive interpretors. Reactive scripts
interpretors can run several commands in parallel and manage broadcast
events. Instants of reactive scripts are actually identified to the
reactions of the interpretor. The Language of Reactive Scripts is a
mix of two formalisms: the
SL synchronous language, and the
ROM
model.
A Reactive Scripts interpretor called rsi-tk has been implemented in Reactive-C, using the graphical
toolkit Tcl/Tk as interpretor of basic actions. An interpretor of
Reactive Scripts has also been developped by Jean-Ferdy Susini with
SugarCubes.
Icobj Programming is a simple and fully
graphical programming method, using a powerful means to combine
behaviors. This programming is based on the notion of an
icobj
which has a behavioral aspect (object part), a graphical aspect (icon
part), and which can be animated at screen.
Icobj Programming comes from the reactive approach and provides
parallelism, broadcast event communication and migration through the
network.
Several experimental systems based on this approach are
implemented. A first Icobjs system is implemented with Reactive
Scripts in Reactive-C and Tcl/Tk. It is present in the software distribution related to
Reactive-C. This experimental system has been awarded by
Pirelli
The new Icobjs system is now implemented in Java.
It is used for simulations in Physics, in the context of games, and for
interpretation of the Ambient calculus. The new system is
described in Chritian Brunette's thesis.
SugarCubes is a set of Java classes
for implementing:
- event based systems, especially those where events are
instantly broadcast throughout the system. Communicating in this framework
is like in radio transmissions, where emitters send information that
is instantaneously received by all receivers.
- concurrent systems, in particular thread-less ones. Here,
parallelism is a logical programming construct to implement activities
which are supposed to proceed concurrently and not one after the
other.
- reactive systems, which continuously react to activations.
A comparison of SugarCubes with the standard Java threading
mechanism is available. It shows that SugarCubes proposes a simple and
structured approach to concurrency which can be seen as an alternative
to Java threads, especially when dynamic combinations of communicating
concurrent components are needed.
The version 3 of SugarCubes is described in the
thesis of J-F. Susini
Junior is a kernel model for reactive
programming, issued froom
SugarCubes. It basically defines
concurrent reactive instructions communicating with broadcast
events. At the basis of
Junior is the rejection of immediate
reaction to absence, which is one of the major difference with
synchronous formalisms.
The parallel operator in Junior is basically non-deterministic. This
is the main difference with SugarCubes which is totally deterministic.
Operational semantics has been provided for Junior.
Junior has an efficient implementation in which the whole
program has not to be walked through at each micro-step. In this
implementation, developped by Laurent Hazard, instructions stuck on
events are stored in queues, and generation of an event directly fires
all instructions stuck on it. Others implementations have been
developped in various contexts; one of them is under construction by
Louis Mandel.
REJO
isv an extension of Java that defines
reactive objects having their own data and their own set of
reactive instructions. These objects might also be considered as
mobile agents which can migrate using a platform, named
ROS,
based on JavaRMI.
REJO and ROS are built over Junior. The programming model
of REJO is close to that of Junior and SugarCubes and
produces reactive instructions that are executed in a reactive
machine.
REJO and ROS are described in details in the
thesis of R. Acosta-Bermejo
FairThreads offers a very simple
framework for concurrent and parallel programming. Basically, it
defines
schedulers which are synchronization servers, to which
fair threads are linked. All threads linked to the same scheduler are
executed in a cooperative way, at the same pace, and they can
synchronize and communicate using broadcast events. Threads which are
not linked to any scheduler are executed by the OS in a preemptive
way, at their own pace.
FairThreads is implemented in C, Java, and
Scheme. Implementations differ by the way unlinked threads are
defined. In Scheme, unlinked threads, called service threads,
are not user-defined. In Java and C, unlinked threads are mapped to
kernel threads and programming constructs are provided for dynamically
linking and unlinking threads.
LOFT is a thread-based language for
concurrent programming in C.
LOFT is closely related to
FairThreads (actually,
LOFT stands for
Language Over Fair
Threads). Objectives are:
- to make concurrent programming simpler and safer by providing
a framework with a clear and sound semantics.
- to get efficient implementations which can deal with large
numbers of concurrent components.
- to allow lightweight implementations that can be used in the
context of embedded systems with limited resources.
- to be able to benefit for parallelism provided by SMP
multiprocessor machines.