By Suzanne Ross with Nick Benton and Gavin Bierman
June 13, 2005 12:00 AM PT
Life is simple when you work alone and only have to do one thing at a time. If you conduct all your business on the telephone, when you ask a question, you can just wait for the answer; when it comes, you can safely assume it was an answer to the question you just asked.
For a long time, most programming was similarly simple. Only the wizards who wrote operating systems or the core engines for databases wrote software that had to do more than one thing at once, called concurrent programming. The typical application programmer mostly wrote sequential programs that did one thing at a time, with exclusive access to all the data they needed.
But just as we increasingly have to juggle, multitask and cooperate in our everyday lives, computer programs increasingly have to work together and do more than one thing at once. Modern network-centric applications get the job done by communicating with many other Web services and applications, as well as with users. An application that only sent one message at a time to other services and locked its graphical user interface until it received a response would be practically unusable, just as a business that closed whenever it was waiting for a reply to a letter would quickly go bankrupt.
Nick Benton and Gavin Bierman, scientists from Microsoft Research in Cambridge, have designed an experimental research language that extends C# with new features for writing concurrent programs. A compiler for the language, called Cω (C Omega), is available to the public.
“Concurrent programming is notoriously difficult,” Benton said. “Cω makes it significantly easier for developers to write correct concurrent programs. We have a simple model of concurrency that works both for multiple threads on a single machine and for dealing with asynchronous communication between multiple machines.”
Some of the challenges in writing concurrent programs involve keeping tasks from interfering with each other. Programmers use “locks” to make tasks wait in line for access to resources, similar to the way in which access to a piece of railway track is controlled by signals. Using locks incorrectly can cause “deadlock,” a situation in which tasks become blocked, forever waiting for one another, or “livelock,” in which tasks loop without ever making progress, like two people stuck in a doorway who both keep saying, “No, after you.” Forgetting a lock can lead to two operations simultaneously accessing the same piece of data and getting inconsistent results, possibly leading to a crash.
Not only is it hard to get lock usage right when writing a program, but finding mistakes by testing and debugging is much more difficult for concurrent programs than for sequential ones. The interactions between tasks can be different each time a program is run, leading to “Heisenbugs”—errors that disappear when you look for them—or subtle bugs that first manifest themselves after a program has run correctly for years.
As well as dealing with concurrency, many developers have to write applications that interoperate with databases and process XML data.
“Typical enterprise applications have a relational database at the back, a middle tier of business logic written in C#, and an XML or HTML presentation tier at the front,” Bierman said. “That’s three different data models, and people spend a lot of time and effort just converting between them. One of the things we’ve done with Cω is to go a long way toward unifying those models so programmers can concentrate on their logic.”
Bierman began working at Microsoft Research in March 2004. He had consulted with researchers in Cambridge and Redmond before that, being conveniently located next door as a professor at the University of Cambridge. “I was working to develop extensions to C# to deal with relational databases and XML. At that time, the language was called Xen,” Bierman said.
Benton had worked with Luca Cardelli and Cédric Fournet of Microsoft Research Cambridge to develop a concurrent programming language called Polyphonic C#. The two researchers combined the research from Polyphonic C# and Xen into Cω.
“With Cω, we’ve addressed two of the things that make life most difficult for developers today,” Benton said. “We’ve extended the C# language to make it more useful for writing concurrent programs and programs that access databases and manipulate XML. These are both exciting and challenging research areas, and there’s still a lot more to explore.”