5.6.3  Concurrent Programming

Mythryl is a fork of the SML/NJ codebase. SML was standardized in 1990 and is defined as a single-threaded language, but SML/NJ supports callcc and SML/NJ’s stackless implementation makes callcc about 100X faster than in typical stack-based languages; This makes SML/NJ an excellent foundation upon which to build a concurrent programming language.

Mythryl (and more broadly ML-family languages) are wonderful candidates for concurrent and parallel programming because the problems with concurrent and parallel programming all revolve around heap side effects, and ML code typically uses only about one percent as many side effects as equivalent code in mainstream imperative languages like C/C++/Java/etc. One hundred times fewer side effects translates directly to one hundred times fewer race condition bugs, clobbered-shared-variable bugs and so forth. The typesafety provided by ML-family languages is also very welcome in the context of concurrent and parallel programming, because they mean fewer runtime bugs, and runtime debugging is inherently more difficult in concurrent and parallel programs than in old-style single-threaded programs.

Starting in about 1990 John H Reppy developed a concurrent programming library for SML called CML ("Concurrent ML"), documented in his book of that title.

This library has been integrated into the Mythryl codebase and work is under way to make concurrent programming the norm in Mythryl. At present, however, concurrent programming in Mythryl is experimental and uses a separate set of libraries. (The Mythryl codebase pervasively assumes single-threaded operation; making it all threadsafe and concurrent-programming oriented will take a lot of detail work.)

The Mythryl port of CML is called "threadkit", and is not well documented because the code is still evolving steadily. For an informal overview of what is working so far, take a peek at


in the Mythryl sourcecode distribution.

As a quick sketch of the current threadkit facilities:

By far the largest body of code written in CML is eXene, the X widgetset and and client library that John H Reppy wrote to exercise CML. The Mythryl port of eXene is called xkit and the code may be found in src/lib/x-kit/ in the Mythryl source distribution.

This code is an ambitious experiment in highly concurrent programming. Each widget uses at least one private thread to animate it, and often more. In retrospect some of the ideas tried out in this package worked very well and some worked not very well at all.

One of the biggest design problems turned out to be using primarily synchronous communication between widgets (i.e. mailslots) while also having widgets send to both parent and child widgets; this proved a fertile breeding ground for deadlock bugs. (If I were redesigning it today I would use mailqueues as the primary interthread communication mechanism.)

Since xkit needs a fairly complete rewrite to bring it up to production quality (and since Gtk is more apropos for most purposes) I have not yet written a tutorial set for it, but sample apps may be found in


and using the widget kit is not terribly difficult working from these examples plus an occasional peek at the widget library sourcecode and/or the original eXene documents.

Comments and suggestions to: