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...