Java Threads in the light of CSP

Professor Peter Welch
University of Kent at Canterbury
<phw@ukc.ac.ukl>


Java provides support for parallel computing through a model that is built into the language itself. However, the designers of Java chose to be fairly conservative and settled for the concepts of threads and monitors. Monitors were developed by Tony Hoare, Brinch Hansen and others in the early 1970s as a structured way of using semaphores to control access to shared resources. Hoare climbed away from this and broke entirely new ground in the late 1970s with the theory of Communicating Sequential Processes (CSP).

A serious problem with monitors (and their accompanying condition variables) is that to write and reason about one of its methods means having to write and reason about all its methods at the same time. This does not scale! As the complexity of the system we are trying to control grows, we get a combinatorial explosion in the logic required to implement that control. One of the great achievements of CSP is that this does not happen -- the semantics of each method are WYSIWIG (i.e. we can write and reason about each one separately). Yet all we are offered by Java are those monitors.

Fortunately, it is possible to introduce the CSP model into Java through sets of classes implemented on top of its monitor support. By restricting interaction between active Java objects to CSP synchronisation primitives, Java thread semantics become compositional and system complexity can be ramped up with linear increase in effort. Multi-threaded Web applets and distributed applications become simpler to design and implement, race hazards never occur, difficulties such as starvation, deadlock and livelock are easier to confront and overcome, and performance is no worse than that obtained from directly using the raw monitor primitives.

The advantages of teaching parallelism in Java purely through the CSP class libraries will be discussed. These libraries were developed jointly at Kent and Oxford Universities in the UK and the University of Twente in the Netherlands.


Volgende >
<Terug naar de inhoudsopgave

14 oktober 1997