Lambda the Ultimate

inactiveTopic CSP for Java
started 7/18/2001; 4:09:32 AM - last post 7/19/2001; 8:08:20 AM
Ehud Lamm - CSP for Java  blueArrow
7/18/2001; 4:09:32 AM (reads: 1051, responses: 3)
CSP for Java
Java implementation of the CSP concurrent programming model.

I haven't used this library, but I do know that CSP is much better than the normal Java concurrency facilities. (As you recall I am teaching Ada, and the Ada tasking model is based on CSP. You can read about that in the Ada design docs, which can be found via our design-docs page).


Posted to general by Ehud Lamm on 7/18/01; 4:10:16 AM

Ehud Lamm - Re: CSP for Java  blueArrow
7/19/2001; 5:39:38 AM (reads: 1043, responses: 0)
Thought, I'd share some experiences. I am playing around building an Ada program producing the Hamming numbers (2^i*3^j*5^k). Well, I am sort of doing a heuristic search of the solution space. Basically, the idea is to use Ada tasks to implement a stream data structure. But things can get interesting pretty quick.

Ada tasks do not support polymorphism. This menas that if I have a task that knows how to produce a stream that is the result of merging two input streams, the task itself isn't a stream.

To overcome this kind of problem we encapsulate the tasks inside tagged types (the Ada inheritance mechanism). This can be done almost elegantly, though this exercise makes you wonder whether the "everything's an object" crowd actually got it right all along.

Tasks which are intended for concurrency allow you some control over the control-flow of your system. However, this is not enough. The streams are not just producers, churning out numbers. The stream object itself shouldn't change as you produce more numbers. The elements of the stream remain the same, it is just the at a certain moment we are examining one specific element in the middle of the series. Obviously, the stream object under goes changes - but these shouldn't be visible. The outside view is that of an immutable object.

These are just some of the issues this little problem raises. I thought about writing about it here, because in a sense this problem shows how threads and CSP are themselves pretty low level abstraction mechanisms. The fact that they are better than the original Java approach, doesn't mean all that much...

John Lawter - Re: CSP for Java  blueArrow
7/19/2001; 7:04:24 AM (reads: 1043, responses: 1)
One question: when you say that you "encapsulate the tasks inside tagged types", how does that work ? I thought that tasks in Ada were equivalent to modules, so I'm a bit confused.

Ehud Lamm - Re: CSP for Java  blueArrow
7/19/2001; 8:08:20 AM (reads: 1126, responses: 0)
Ada tasks are not like modules. In Ada tasks are essentially types (well, you can have singelton tasks, but let's leave that aside). Module in Ada are packages. The language is quite orthogonal in is this respect.

For example the definition of a stream maybe something like:

type Stream(P:Natural) is new Streams.Stream with
     record
       T:Stream_T(P);
     end record;

Where Stream_T is a task type. This declaration means that Stream is inherited from Streams.Stream, the Stream type in package Streams, and extends it with the T field, of the type Stream_T.

The Ada 83 Rationale explains the design decisions behind Ada tasking facilities.