Tasks: Language Support for Event-driven Programming

ACM SIGPLAN 2007 Workshop on Partial Evaluation and Program Manipulation (PEPM 2007), Nice, France, January 15-16, 2007.
Jeffrey Fischer, Rupak Majumdar, Todd Millstein
The event-driven programming style is pervasive as an efficient method for interacting with the environment. Unfortunately, the event-driven style severely complicates program maintenance and understanding, as it requires each logical flow of control to be fragmented across multiple independent callbacks.

We propose tasks as a new programming model for organizing event-driven programs. Tasks are a variant of co-operative multi-threading and allow each logical control flow to be modularized in the traditional manner, including usage of standard control mechanisms like procedures and exceptions. At the same time, by using method annotations, task-based programs can be automatically and modularly translated into efficient event-based code, using a form of continuation passing style (CPS) translation. A linkable scheduler architecture permits tasks to be used in many different contexts.

We have instantiated our model as a backward-compatible extension to Java, called TaskJava. We illustrate the benefits of our language through a formalization in an extension to Featherweight Java, and through a case study based on an open-source web server.


[PDF]