JCSP

Last updated

JCSP is an implementation of communicating sequential processes (CSP) for the programming language Java. [1]

Contents

Although CSP is a mathematical system, JCSP does not require in-depth mathematical skill, allowing instead that programmers can achieve well-behaved software by following simple rules.

Overview

There are four ways in which multi-threaded programs can fail untestably: [1]

Generally, it is not possible to prove the absence of these four hazards merely by rigorous testing. Although rigorous testing is necessary, it is not sufficient. Instead it is necessary to have a design that can demonstrate these four hazards don't exist. CSP allows this to be done using mathematics and JCSP allows it to be done pragmatically in Java programs.

The benefit of the basis in mathematics is that stronger guarantees of correct behaviour can be produced than would be possible with conventional ad hoc development. Fortunately, JCSP does not force its users to adopt a mathematical approach themselves, but allows them to benefit from the mathematics that underpins the library.

Note that the CSP term process is used essentially as a synonym for thread in Java parlance; a process in CSP is a lightweight unit of execution that interacts with the outside world via events and is an active component that encapsulates the data structures on which it operates.

Because the encapsulation of data is per-thread (per process in CSP parlance), there is typically no reliance on sharing data between threads. Instead, the coupling between threads happens via well-defined communication points and rendezvous. The benefit is that each thread can broadly be considered to be a "single-threaded" entity during its design, sparing the developer from the uncertainties of whether and where to use Java's synchronized keyword, and at the same time guaranteeing freedom from race conditions. JCSP provides for clear principles for designing the inter-thread communication in a way that is provably free from deadlock.

There is a clear similarity between some classes in the standard Java API (java.util.concurrent) and some in JCSP. JCSP's channel classes are similar to the BlockingQueue. There is one important difference: JCSP also provides an Alternative class to allow selection between inputs; this capability is absent from the standard Java API. Alternation is one of the core concepts that CSP uses to model events in the real world.

Alternative was proven to operate correctly by exhaustive mathematical analysis of its state space, guaranteeing it can never in itself cause a deadlock. [2] As such, it epitomises the dependability of JCSP from its mathematical basis.

Networking Layer

Because Transmission Control Protocol (TCP) sockets can be constructed to behave as blocking channels in the CSP sense, it is possible to distribute JCSP processes across multiple computers. This is achieved using the JCSP Net extension that provides channels with CSP semantics using TCP. Because CSP is compositional, it does not matter in behaviour terms whether processes are co-located or distributed. The only difference is in the relative performance. So it is possible, for example, to develop an application on a single server then compare multi-processor version of the same application with the aim of optimising the performance.

Other versions

Robot edition

JCSP re is a highly reduced version of the JCSP packages developed around 2008 at the Napier University Edinburgh by Professor Jon Kerridge, Alex Panayotopoulos and Patrick Lismore. Research into JCSP for robotics environments and JCSP for mobile environments is an active area of research at Napier University Edinburgh. The working implementation of 'JCSP re' allows the development of the same concurrent software for robots. Specifically, the robots targeted for this research were the Lego Mindstorms NXTs because they can run the popular LeJOS NXJ virtual machine that executes Java source code. [3]

Using JCSP from other languages

JCSP is essentially a pure-Java API (although a research alternative exists that uses the C-CSP extension to the JVM). As such, it is in principle eminently suitable for concurrency in Scala and Groovy applications as well as Java ones.

JCSP can therefore provide an alternative to Scala's actor model. JCSP uses synchronised communication and actors use buffered (asynchronous) communication, each of which have their advantages in certain circumstances. JCSP allows its channels to be buffered so can easily emulate the actor model; the converse is not true.

See also

Related Research Articles

<span class="mw-page-title-main">Thread (computing)</span> Smallest sequence of programmed instructions that can be managed independently by a scheduler

In computer science, a thread of execution is the smallest sequence of programmed instructions that can be managed independently by a scheduler, which is typically a part of the operating system. The implementation of threads and processes differs between operating systems. In Modern Operating Systems, Tanenbaum shows that many distinct models of process organization are possible. In many cases, a thread is a component of a process. The multiple threads of a given process may be executed concurrently, sharing resources such as memory, while different processes do not share these resources. In particular, the threads of a process share its executable code and the values of its dynamically allocated variables and non-thread-local global variables at any given time.

Thread safety is a computer programming concept applicable to multi-threaded code. Thread-safe code only manipulates shared data structures in a manner that ensures that all threads behave properly and fulfill their design specifications without unintended interaction. There are various strategies for making thread-safe data structures.

<span class="mw-page-title-main">Lego Mindstorms</span> Hardware and software platform by Lego

Lego Mindstorms is a discontinued hardware and software structure which develops programmable robots based on Lego bricks. Each version includes an intelligent brick, a set of modular sensors and motors, and parts from the Lego Technic line to create mechanical systems. The system is controlled by the hub, which acts as the brain of the mechanical system.

In computer science, a lock or mutex is a synchronization primitive: a mechanism that enforces limits on access to a resource when there are many threads of execution. A lock is designed to enforce a mutual exclusion concurrency control policy, and with a variety of possible methods there exists multiple unique implementations for different applications.

In computer science, communicating sequential processes (CSP) is a formal language for describing patterns of interaction in concurrent systems. It is a member of the family of mathematical theories of concurrency known as process algebras, or process calculi, based on message passing via channels. CSP was highly influential in the design of the occam programming language and also influenced the design of programming languages such as Limbo, RaftLib, Erlang, Go, Crystal, and Clojure's core.async.

The calculus of communicating systems (CCS) is a process calculus introduced by Robin Milner around 1980 and the title of a book describing the calculus. Its actions model indivisible communications between exactly two participants. The formal language includes primitives for describing parallel composition, choice between actions and scope restriction. CCS is useful for evaluating the qualitative correctness of properties of a system such as deadlock or livelock.

In computer science, message queues and mailboxes are software-engineering components typically used for inter-process communication (IPC), or for inter-thread communication within the same process. They use a queue for messaging – the passing of control or of content. Group communication systems provide similar kinds of functionality.

In computing, a memory barrier, also known as a membar, memory fence or fence instruction, is a type of barrier instruction that causes a central processing unit (CPU) or compiler to enforce an ordering constraint on memory operations issued before and after the barrier instruction. This typically means that operations issued prior to the barrier are guaranteed to be performed before operations issued after the barrier.

<span class="mw-page-title-main">Concurrency (computer science)</span> Ability to execute a task in a non-serial manner

In computer science, concurrency is the ability of different parts or units of a program, algorithm, or problem to be executed out-of-order or in partial order, without affecting the outcome. This allows for parallel execution of the concurrent units, which can significantly improve overall speed of the execution in multi-processor and multi-core systems. In more technical terms, concurrency refers to the decomposability of a program, algorithm, or problem into order-independent or partially-ordered components or units of computation.

<span class="mw-page-title-main">Pipeline (Unix)</span> Mechanism for inter-process communication using message passing

In Unix-like computer operating systems, a pipeline is a mechanism for inter-process communication using message passing. A pipeline is a set of processes chained together by their standard streams, so that the output text of each process (stdout) is passed directly as input (stdin) to the next one. The second process is started as the first process is still executing, and they are executed concurrently. The concept of pipelines was championed by Douglas McIlroy at Unix's ancestral home of Bell Labs, during the development of Unix, shaping its toolbox philosophy. It is named by analogy to a physical pipeline. A key feature of these pipelines is their "hiding of internals". This in turn allows for more clarity and simplicity in the system.

The actor model in computer science is a mathematical model of concurrent computation that treats an actor as the basic building block of concurrent computation. In response to a message it receives, an actor can: make local decisions, create more actors, send more messages, and determine how to respond to the next message received. Actors may modify their own private state, but can only affect each other indirectly through messaging.

In computer science, the Actor model and process calculi are two closely related approaches to the modelling of concurrent digital computation. See Actor model and process calculi history.

In computer science, future, promise, delay, and deferred refer to constructs used for synchronizing program execution in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, usually because the computation of its value is not yet complete.

Concurrent computing is a form of computing in which several computations are executed concurrently—during overlapping time periods—instead of sequentially—with one completing before the next starts.

The actor model and process calculi share an interesting history and co-evolution.

A network socket is a software structure within a network node of a computer network that serves as an endpoint for sending and receiving data across the network. The structure and properties of a socket are defined by an application programming interface (API) for the networking architecture. Sockets are created only during the lifetime of a process of an application running in the node.

<span class="mw-page-title-main">Lego Mindstorms NXT</span> Programmable robotics kit

Lego Mindstorms NXT is a programmable robotics kit released by Lego on August 2, 2006. It replaced the first-generation Lego Mindstorms kit, which was called the Robotics Invention System. The base kit ships in two versions: the Retail Version and the Education Base Set. It comes with the NXT-G programming software, or optionally LabVIEW for Lego Mindstorms. A variety of unofficial languages exist, such as NXC, NBC, leJOS NXJ, and RobotC. The second generation of the set, the Lego Mindstorms NXT 2.0, was released on August 1, 2009, featuring a color sensor and other upgraded capabilities. The third generation, the EV3, was released in September 2013.

The Java programming language and the Java virtual machine (JVM) is designed to support concurrent programming. All execution takes place in the context of threads. Objects and resources can be accessed by many separate threads. Each thread has its own path of execution, but can potentially access any object in the program. The programmer must ensure read and write access to objects is properly coordinated between threads. Thread synchronization ensures that objects are modified by only one thread at a time and prevents threads from accessing partially updated objects during modification by another thread. The Java language has built-in constructs to support this coordination.

Join-patterns provides a way to write concurrent, parallel and distributed computer programs by message passing. Compared to the use of threads and locks, this is a high level programming model using communication constructs model to abstract the complexity of concurrent environment and to allow scalability. Its focus is on the execution of a chord between messages atomically consumed from a group of channels.

<span class="mw-page-title-main">Lego Mindstorms EV3</span>

LEGO Mindstorms EV3 is the third generation robotics kit in LEGO's Mindstorms line. It is the successor to the second generation LEGO Mindstorms NXT kit. The "EV" designation refers to the "evolution" of the Mindstorms product line. "3" refers to the fact that it is the third generation of computer modules - first was the RCX and the second is the NXT. It was officially announced on January 4, 2013, and was released in stores on September 1, 2013. The education edition was released on August 1, 2013. There are many competitions using this set, including the FIRST LEGO League Challenge and the World Robot Olympiad, sponsored by LEGO.

References

  1. 1 2 Belapurkar, Abhijit (21 June 2005). "CSP for Java programmers". IBM DeveloperWorks. Retrieved 2007-04-20.
  2. Welch, Peter; Martin, Jeremy (2000). Formal Analysis of Concurrent Java Systems. Communicating Process Architectures 2000 (Report).
  3. Jon Kerridge; Alex Panayotopoulos; Patrick Lismore (2008). "JCSPre: the Robot Edition to Control LEGO NXT Robots". Concurrent Systems Engineering Series Volume 66: Communicating Process Architectures 2008. IOS Press Books: 255–270. doi:10.3233/978-1-58603-907-3-255. Archived from the original on 2010-04-18.{{cite journal}}: CS1 maint: bot: original URL status unknown (link)