Serial Event Processing or RTC (run to completion) is not the same as a lack
of multi-threading. I think this point may have been misunderstood from my
earlier post. Here's a bit more info... it's a moderately short excerpt from
a 1997 paper... you have to read down a bit to get to the description of
"actors", which is one half of the foundation of Quantum Programming. QP is
founded on the 2 fundamental concepts of hierarchical state machines and
active object-based computing.
The Vision
Multi-threading Without Headaches
Conventional Approach
It is generally acknowledged today that multithreading applications or
agents confers
many benefits: improved scalability, improved responsiveness to external
stimuli,
improved modularity, and so forth. The question before us is not whether
multithreading
is desirable, but rather how best to introduce multithreading within an
application as well
as effect communication and synchronization between threads.
The general practice in this regard - sometimes called free threading -- is
ad-hoc,
proceeding largely as follows. A multiplicity of threads are spawned, each
anchored at an
associated object (e.g. communication socket, timer, console event loop, a
semaphore)
where they each block pending an event (UDP packet, time-out, mouse event,
semaphore signal(), respectively). Once awakened a thread will typically
course through
a mesh of objects, entering each by invocation of a class method according
to the
operation to be performed. This chain reaction may be suspended for a time,
due to
preemption by another thread, or pending completion of some action, a
time-out, etc.
Finally, having completed all processing, the thread withdraws back to its
lair where it
resumes its vigil for fresh stimuli.
There are many problems with this and other related approaches:
* Race-conditions: special precautions much be taken to avoid
race-conditions
when two threads collide on the same object.
* Deadlock: the previous problem is typically averted through the use of
mutex
semaphores. This practice may give rise to deadlock (or worse yet, unwanted
reentrancy)
should a thread, over the course of its wanderings, loop back in a cycle
to an object through which is already threaded.
* Architectural Constraints: the need for deadlock avoidance may require the
needless imposition of strictly layered architectures that preclude cyclic
threading, thereby limiting the range of options open to a designer.
* Non-determinism: unless one knows in advance the maximum span of time a
thread may spend traversing a mesh of objects, other threads may be locked
out, for indeterminate periods, of objects on their path currently threaded
by
another thread.
* Complexity: Averting the previous problems may require careful
partitioning of
the object space among threads responsible for their animation, a judicious
assignment of thread priorities, and the introduction of inter-thread
synchronization and communication primitives as needed to effect changes
across partition boundaries. Regrettably, the miscellaneous instruments used
for
this purpose, such as counting and mutex semaphores, message queues,
monitors -- the pins and needles of the system programmer's subtle craft
should not be entrusted to the use of a typical application programmer, lest
subtle intermittent faults be introduced into the workings of a system,
faults
notoriously hard to reproduce, isolate and correct.
Actor Based Multithreading
For these and other reasons the distributed operating system community
(which
encountered problems very similar to those listed above while building
scalable network
operating systems) has been gravitating toward micro-kernel architectures. A
microkernel
Operating System is built on top of a small message-passing nucleus by
addition
of light-weight threaded concurrent server components that communicate with
one
another and their application level clients through message passing. In
particular, use of
message-passing implies, in theory at least, that components need not be
co-located in
the same host to communicate.
When this message-passing model is applied to the realm of objects it yields
the notion of
actors: active event driven objects endowed with a locus of control. While
it is certainly
true that counting semaphores, mutexes, monitors will serve most honorably
in the
construction of an Actor Framework, base actor classes and the
message-passing
apparatus, these often troublesome instruments need not be used by
application
programmers directly.
The most salient characteristics of actor-based multithreading are these:
* Serial Event Processing: Actors process one event at a time, to
completion,
according to a prescribed event scheduling discipline (e.g. priority/FIFO,
Actor
receptivity).
* Atomic Event Processing: Event processing is atomic, that us to say
indivisible
and instantaneous at a logical level. Accordingly, application level
critical sections can
be avoided through the introduction of a server actor responsible for a
shared
resource or service, together with an associated service protocol.
* Asynchronous Event Processing: Regardless of the scheduling model that is
employed (e.g. free or partitioned threading or both) an actor can view all
messageborne
interactions with its peers as occurring asynchronously. Towards this end,
incoming messages are automatically queued within the target actor should it
be
"busy" (i.e. already threaded), or mapped to another thread partition, this
without
need of any involvement by application programmers. Thus whenever a request
message is sent to from one actor to another, any response message that
might be
forthcoming will be subject to processing in due time. Should the response
reach the
service requester while it lingers still in a transaction - perhaps the very
transaction
that evinced the response -- the response is simply queued for subsequent
service,
at the first opportune moment. In this way deadlocks are avoided and
designers
regain the architectural license to build as they see fit, untrammeled by ar
bitrary
layering restrictions.
All Rights Reserved © 1997 Charis Software Systems, Inc.
The whole paper is available from the links I provided in my earlier post.