Next: CML
Up: Literature on Threads in
Previous: Introduction
Among the first successful implementations of threads in Functional
Programming Languages was the work by Cooper and Morrisett
[7] in which they describe how threads have been added to
Standard ML by providing an SML Module that handles threads, without
making any modifications to the SML language syntax.
- A thread module provides fork control structures to
create threads. Fork is a function that starts an invocation of its
argument executing as an independent thread of control. The effect is
to have two threads, the parent (the thread that invoked fork) and the
child (the thread that executes the argument passed to fork).
- No join control structure is required as thread
termination occurs either implicitly on returning from its call or
explicitly when exit is used.
- Communication between the threads is via shared mutable
objects. Mutual exclusion between threads is managed using
mutex locks with acquire and release
operations. A busy waiting version of acquire uses
try_acquire . Another operation with_mutex acquires
mutex during the function execution releasing it before the return
from the function.
- Synchronisation and termination of threads is via wrapper
functions. Synchronisation between threads is achieved using condition
variables which are implemented using condition , a function to
create a new condition variable, mutex_of , a function to
return the mutex associated with a condition, with_condition
function which is just the composition of with_mutex and
mutex_of , signal operation to signal the occurrence of
an event, broadcast operation to signal to awaken all threads
waiting for the condition, wait operation to wait for a
specified condition variable; also provided are await to test
before wait operation and yield to allow scheduling another
thread on the current processor.
- var type is provided for thread states. This allows
independent thread identification in different subsystems.
- It is claimed that higher level abstractions like Recursive
Mutual Locks, Futures (as in Multilisp), Channels, CSP guard commands,
Ada rendezvous and select, and Reppy's events could be built on top of
these basic constructs.
- Two different implementations using continuations are discussed:
one uses coroutines for multiplex control, and another uses signals
and asynchronous signal handling facility for preemption.
- Modifications of this thread package for multiprocessor
implementation such as with Mach operating systems [21] are discussed [9] & [1].
- Comparison with C-coroutines and C/Mach suggest optimisations
are required. No asynchronous communication with the threads is
available in the current implementations.
- Formally, integration of SML with threads really requires a
new definition of SML. It is suggested that a dynamic semantics of
SML/Mach using CSP or CCS concurrency models might provide a firm
theoretical basis for such a threads extended SML.
Next: CML
Up: Literature on Threads in
Previous: Introduction
Ananda Amatya
2/16/1999