Commit 0312839e authored by jjgarcia's avatar jjgarcia

Remove documentation of the old implementation of threads

parent 4eac7977
......@@ -528,7 +528,7 @@ Enumeration type which distinguishes the different types of lisp objects. The
most important values are t_cons, t_fixnum, t_character, t_bignum, t_ratio,
t_shortfloat, t_longfloat, t_complex, t_symbol, t_package, t_hashtable,
t_array, t_vector, t_string, t_bitvector, t_stream, t_random, t_readtable,
t_pathname, t_bytecodes, t_cfun, t_cclosure, t_gfun, t_instance, t_cond and
t_pathname, t_bytecodes, t_cfun, t_cclosure, t_gfun, t_instance, t_foreign and
@end deftp
......@@ -1501,7 +1501,6 @@ generic functions of CLOS.
@item @code{gfun} @tab @code{none (CLOS generic-function)}
@item @code{instance} @tab @code{none (CLOS instance)}
@item @code{thread} @tab @code{none (thread)}
@item @code{cont} @tab @code{none (continuation)}
@end multitable
......@@ -3651,289 +3650,7 @@ of the slot.
@node Multithread, Everything, CLOS, Top
@chapter Multithread
The goals of the present design are to provide a minimal set of facilities,
which stand directly on the core of the @llisp{} computational model, and which
provide the maximum degree of flexibility to build higher level concurrency and
synchronization constructs.
In particular we wanted a system which:
@item is semantically based
@item is flexible enough to allow freedom to experiment new constructs
@item blends with the functional nature of @llisp{}
@item blends with object-oriented programming
@end itemize
We have achieved this by taking the fundamental concepts of denotational
description of functional languages like @llisp{} and making them accessible
within the programming language itself according to the technique of reflection
We show several examples of how typical concurrent programming constructs can
be implemented using these primitives.
* Model::
* Manual Section::
@end menu
@node Model, Manual Section, Multithread, Multithread
@section Model
The computational model on which our design is based is the functional model
described with continuation semantics. Processing happens through steps of
function application. Each function invocation is supplied with a
continuation, representing the continuation of the program. Normally as the
last step of each function execution, the continuation is invoked with
arguments the values to be returned by the function. The continuation will then
proceed execution with such values. However the function can instead invoke an
alternative continuation, discarding the continutation it has received. In this
way, the function has the ability to alter the flow of control of the program.
The theory of denotational semantics shows that with this style of description,
any arbitrary control construct can be programmed.
Our approach has been to take this underlying model and to make it visible to
the @llisp{} programmer. Control flow proceed normally through function calls,
unless the program requests to access its continuation. It can then decide
whether it wants to resume such continuation at the end, thereby proceeding
normally, or to discard that continuation and proceed in a different
way. Continuations are first-class objects which can be passed as arguments or
returned as values from functions.
Given this model of computation, the only addition which is necessary to be
able to handle concurrency is the ability to create multiple threads of
execution. Control of flow among different threads is obtained just by the use
of continuations.
* Threads::
* Continuations::
* Concurrency::
* Mixed computations::
@end menu
@node Threads, Continuations, Model, Model
@subsection Threads
A thread identifies one sequential flow of execution. A thread contains all the
dynamic information needed by the @llisp{} executor. A list of active threads
is managed by a scheduler, which switches execution among them at the
expiration of a time slice or when a thread gets suspended.
The structure of a thread is roughly as follows:
@center @b{Thread}
@center Function
@center Runtime Stack(s)
@center Program Counter
@center CPU Registers
@center @b{Next Thread}
@center @dots{}
@node Continuations, Concurrency, Threads, Model
@subsection Continuations
A @tindexed{continuation} represents a thread suspended at a particular point
in its execution, when it is expecting some return values from a procedure call
or some arguments to a procedure. Since a continuation can be resumed only
once, each continuation is unique.
@node Concurrency, Mixed computations, Continuations, Model
@subsection Concurrency
Actors can be activated concurrently by means of the send primitive. When send
is invoked, a new @emph{thread}, is created for processing the message by the
actor, unless the @emph{actor} is already running. In the latter case, the
message will be just enqueued within the actor.
During the execution of the actor, any function called within the body of the
actor will use the stack of the new thread. Only using one of the message
passing primitives like @emph{send} and @emph{reply} the execution will switch
to a different stack.
@node Mixed computations, , Concurrency, Model
@subsection Mixed Computations
In our model computation can proceed in two ways. One way corresponds to the
traditional sequential execution with function invocation and return, always
running within a single thread; the second way enables parallel execution where
function activations proceed concurrently, each one in a separate thread.
Activation and exchange of data is obtained with the primitive @code{resume}.
A relevant feature or our approach is that the message passing primitives are
just a generalization of the call/return mechanism, and therefore it is
possible for the two mechanisms to cohexist easily and neatly.
@node Manual Section, , Model, Multithread
@section Manual Section
The present design is structured in two levels. The first level introduces the
new data types continuation and thread, and provides a set of primitives to
create and operate on them. Using these primitives it is already possible to
generate and control concurrent computations expressed in terms of @clisp{}
The second level is built on top of the facilities of the first level. By
exploiting the capability to get a hold and manipulate continuations, the
second level provides a set of constructs for concurrent object oriented
programming. Concurrent activities can be generated by using the asynchronous
send construct. Synchronization is provided through serialization of message
processing by an actor.
* Primitives::
@end menu
@node Primitives, , Manual Section, Manual Section
@subsection Primitives
Two new data types are introduced into the language:
@item thread
@item continuation
@end itemize
* Thread primitives::
* Continuation primitives::
* Scheduler primitives::
@end menu
@node Thread primitives, Continuation primitives, Primitives, Primitives
@subsubsection Thread Primitives
@defun {make-thread} {function @keys :cont :name :size}
@var{function} may be a compiled-code object, or a lambda-expression, or a
symbol; in the latter case the global functional value of that symbol is used
(which cannot be a special form nor a macro). make-thread creates a new thread
ready to execute @var{function}. The thread is in a @cindexed{SUSPENDED} status
and does not run. A thread can be put into execution only by making a
continuation for it and issuing a resume to such continuation with a list of
@var{name} is a symbol or string used to identify the thread. @var{size} is
the dimension of the evaluation stack to be used by the thread.
@end defun
@defun {deactivate} {thread}
It stops a @cindexed{RUNNING} @code{thread}, removing it from the queue of
active threads, and sets its status to @cindexed{STOPPED}. A stopped thread can
be resumed with reactivate. Signals an error if the thread is not
@end defun
@defun {reactivate} {thread}
Puts a @cindexed{STOPPED} @var{thread} back into the queue of active threads
for further execution, and sets its status to @cindexed{RUNNING}. Signals an
error if the thread is not @cindexed{STOPPED}.
@end defun
@defun {kill-thread} {thread}
Stops the thread execution and sets its status to @cindexed{DEAD} so that it
will not be run by the scheduler any more. If the status of the @var{thread} is
already @cindexed{DEAD} the function has no effect. Returns @nil{}.
@end defun
@defun {thread-status} {thread}
Returns the status of the @var{thread}, one of the symbols RUNNING,
@cindexed{SUSPENDED}, @cindexed{STOPPED} or @cindexed{DEAD}.
@end defun
@defun {current-thread} {}
It returns the thread within which this function was called.
@end defun
@node Continuation primitives, Scheduler primitives, Thread primitives, Primitives
@subsubsection Continuation Primitives
@defun {make-continuation} {thread @keys{} cont}
Builds a unique new continuation for resuming the @var{thread}. @var{cont} is
an optional continuation to be supplied to the thread. Further
make-continuations on the same thread are disallowed until the last
continuation created has been resumed.
@end defun
@defun {resume} {continuation @rest{} args}
Resumes execution of @var{continuation} and passes it the @var{args}. If
@var{continuation} was created by make-continuation of a function, the behavior
is similar to the behavior of a funcall to that function. However execution
goes on in a separate thread, that is concurrently to the thread which is
issuing the resume. Resume returns immediately the thread which has been
activated. The thread for continuation must be @cindexed{SUSPENDED}, otherwise
resume will produce an error. This could happen if continuation was created
with the result of current-thread and that thread has not been suspended. If
the continuation had already been resumed or timed-out, resume signals an
error. If continuation is @nil{}, resume has no effect. Resume reenables
make-continuation for the thread of @var{continuation}.
@end defun
@defun {pass} {continuation @rest{} args}
same behaviour as @var{resume} except that suspends the current thread.
@var{pass} does not return.
@end defun
@defun {spawn} {function @rest{} args}
Creates a new thread where @var{function} is applied to the @var{args}.
Returns immediately the new thread without waiting for the function to return.
@code{Spawn} behaves like if it were defined as:
(defmacro spawn (function @rest{} args)
`(resume (make-continuation (make-thread ,function)) ,@ args))
@end example
@end defun
@defun {timeout} {delay continuation alternative}
If after @var{delay} seconds @var{continuation} has not been resumed, the
@var{alternative} continuation is resumed and @var{continuation} is marked as
@cindexed{TIMED-OUT}. Returns @nil{} immediately.
@end defun
@node Scheduler primitives, , Continuation primitives, Primitives
@subsubsection Scheduler Primitives
@defun {%disable-scheduler} {}
@code{%disable-scheduler} disables the scheduler, so that the execution of the
current thread will not be interrupted by the scheduler until the function
@code{%enable-scheduler} is called. Returns @nil{}.
@end defun
@defun {%enable-scheduler} {}
@code{%enable-scheduler} enables the scheduler, so that it will time-slice
execution among all the @cindexed{RUNNING} threads. Returns @nil{}.
@end defun
@defun {%suspend} {}
@code{%suspend} sets the status of the current thread to @cindexed{SUSPENDED}
and suspends its execution. The scheduler is enabled again in the same way as
the function @code{%enable-scheduler} does. The thread will proceed execution
@emph{only} when a continuation referring to the thread will be resumed. In
that case @code{suspend} will return the values specified by @code{resume}.
@end defun
[To come once the interface is fixed]
@node Everything, Bibliography, Multithread, Top
@chapter Everything
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment