JCSP
Encyclopedia
In computer science
Computer science
Computer science or computing science is the study of the theoretical foundations of information and computation and of practical techniques for their implementation and application in computer systems...

 and software engineering
Software engineering
Software Engineering is the application of a systematic, disciplined, quantifiable approach to the development, operation, and maintenance of software, and the study of these approaches; that is, the application of engineering to software...

, JCSP is an implementation of Communicating Sequential Processes
Communicating sequential processes
In computer science, Communicating Sequential Processes 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...

 (CSP) for the Java programming language.

Although CSP
Communicating sequential processes
In computer science, Communicating Sequential Processes 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...

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

Overview

There are four ways in which multi-threaded programs can fail untestably:
  • race conditions - shared variables may have indeterminate state because several threads access them concurrently without sufficient locking;
  • deadlock
    Deadlock
    A deadlock is a situation where in two or more competing actions are each waiting for the other to finish, and thus neither ever does. It is often seen in a paradox like the "chicken or the egg"...

    - two or more threads reach a stalemate when they try to acquire locks or other resources in a conflicting way;
  • livelock - similar to deadlock but resulting in endless wastage of CPU time;
  • starvation - one or more threads fail ever to get any work done, compromising the intended outcome of the software algorithms.


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
. As such, it epitomises the dependability of JCSP from its mathematical basis.

Networking Layer

Because TCP
Transmission Control Protocol
The Transmission Control Protocol is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol , and therefore the entire suite is commonly referred to as TCP/IP...

 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.

JCSP Robot Edition

JCSP re
JCSP re
JCSP re stands for "Communicating Sequential Processes for Java, Robot Edition" this is a reduced version of the original JCSP packages and work done at the University of Kent...

 is a highly reduced version of the JCSP packages that were developed at the Napier University
Napier University
Edinburgh Napier is one of the largest higher education institutions in Scotland with over 17,000 students, including nearly 5,000 international students, from more than 100 nations worldwide.-History:...

 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
JCSP re
JCSP re stands for "Communicating Sequential Processes for Java, Robot Edition" this is a reduced version of the original JCSP packages and work done at the University of Kent...

' allows the development of the same concurrent software for robots. Specifically, the robots targeted for this research were the Lego Mindstorms NXTs
Lego Mindstorms NXT
Lego Mindstorms NXT is a programmable robotics kit released by Lego in late July 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...

 because they can run the popular LeJOS
LeJOS
leJOS is a firmware replacement for Lego Mindstorms programmable bricks. It currently supports the LEGO RCX brick and leJOS NXJ supports the NXT brick. It includes a Java virtual machine, which allows Lego Mindstorms robots to be programmed in the Java programming language. It is often used for...

 NXJ virtual machine that executes Java source code.

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
Actor model
In computer science, the Actor model is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent digital computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and...

. JCSP uses synchronised communication and actors used 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.

External links


See also

  • Communicating Sequential Processes
    CSP
    -General:* CSP * Caledonian Steam Packet Company* California Society of Printmakers* California State Parks* Carol Shea-Porter* Center for Security Policy* Civil Services of Pakistan* Certified Safety Professional...

    - the mathematics underlying JCSP
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK