org.jcsp.nxt.lang
Class Parallel

java.lang.Object
  extended by org.jcsp.nxt.lang.Parallel
All Implemented Interfaces:
CSProcess

public class Parallel
extends java.lang.Object
implements CSProcess

This process constructor taks an array of CSProcesses and returns a CSProcess that is the parallel composition of its process arguments.

Shortcut to the Constructor and Method Summaries.

Description

The Parallel constructor taks an array of CSProcesses and returns a CSProcess that is the parallel composition of its process arguments. A run of a Parallel process terminates when, and only when, all its component processes terminate.

Note: for those familiar with the occam multiprocessing language, the Parallel class gives the semantics of the PAR construct. However, none of the parallel usage checks mandated by occam can be made by the Java compiler, so we need to exercise that care ourselves. For instance, do not try to run the same process instance more than once in parallel and, generally, watch out for accidentally shared objects! Running different instances of the same process in parallel is, of course, allowed.

CSProcesses can be added to a Parallel object either via the constructor or the addProcess methods. If a call to addProcess is made while the run method is executing, the extra process(es) will not be included in the network until the next time run is invoked.

CSProcesses can be removed from a Parallel object via the removeProcess or removeAllProcesses method. If a call to removeProcess or removeAllProcesses is made while the run method is executing, the process will not be removed from the network until the next time run is invoked. Non-determinism, of course, needs to be addressed for many applications and is catered for in JCSP by its Alternative construct (which corresponds to the CSP external choice operator and occam ALT) The fact that non-determinism has to be explicitly introduced reduces the chance of overlooking race-hazards caused by that non-determinism.


Constructor Summary
Parallel()
          Construct a new Parallel object initially without any processes.
 
Method Summary
 void addProcess(CSProcess process)
          Add the process to the Parallel object.
(package private) static void addToAllParThreads(java.lang.Thread newThread)
          Adds the thread object to the allParThreads collection.
static void destroy()
          Stops all threads created by all Parallel and ProcessManager objects.
 int getNumberProcesses()
           
(package private) static void removeFromAllParThreads(java.lang.Thread oldThread)
          Removes the thread object from the allParThreads collection.
static void resetDestroy()
          Cancels a call to destroy allowing the JCSP system to be reused.
 void run()
          Run the parallel composition of the processes registered with this Parallel object.
static void setUncaughtErrorDisplay(boolean enable)
          Enables or disables the display or Errors uncaught by a CSProcess running within a Parallel or under a ProcessManager object.
static void setUncaughtExceptionDisplay(boolean enable)
          Enables or disables the display of Exceptions uncaught by a CSProcess running within a Parallel or under a ProcessManager object.
(package private) static void uncaughtException(java.lang.String caller, java.lang.Throwable t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Parallel

public Parallel()
Construct a new Parallel object initially without any processes.

Method Detail

addToAllParThreads

static void addToAllParThreads(java.lang.Thread newThread)
                        throws InterruptedException
Adds the thread object to the allParThreads collection. This should be called by any infrastructure threads when they start.

Parameters:
newThread - the thread to be added to the collection.
Throws:
InterruptedException

removeFromAllParThreads

static void removeFromAllParThreads(java.lang.Thread oldThread)
Removes the thread object from the allParThreads collection.


destroy

public static void destroy()
Stops all threads created by all Parallel and ProcessManager objects. No new threads can be created until the resetDestroy method gets called.


resetDestroy

public static void resetDestroy()
Cancels a call to destroy allowing the JCSP system to be reused. This is provided to that destroy can be called from an Applet's termination method, but the Applet can be restarted later.


addProcess

public void addProcess(CSProcess process)
Add the process to the Parallel object. The extended network will be executed the next time run() is invoked.

Parameters:
process - the CSProcess to be added

getNumberProcesses

public int getNumberProcesses()
Returns:
the number of processes currently registered.

run

public void run()
Run the parallel composition of the processes registered with this Parallel object. It terminates when, and only when, all its component processes terminate.

Implementation note: In its first run, only (numProcesses - 1) Threads are created to run the processes -- the last process is executed in the invoking Thread. Sunsequent runs reuse these Threads (so the overhead of thread creation happens only once).

Specified by:
run in interface CSProcess

setUncaughtExceptionDisplay

public static void setUncaughtExceptionDisplay(boolean enable)
Enables or disables the display of Exceptions uncaught by a CSProcess running within a Parallel or under a ProcessManager object.


setUncaughtErrorDisplay

public static void setUncaughtErrorDisplay(boolean enable)
Enables or disables the display or Errors uncaught by a CSProcess running within a Parallel or under a ProcessManager object.


uncaughtException

static void uncaughtException(java.lang.String caller,
                              java.lang.Throwable t)