gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] PIM SYSTEM implementation using GNU Pthreads


From: Gaius Mulley
Subject: [Gm2] PIM SYSTEM implementation using GNU Pthreads
Date: 26 Aug 2004 22:14:15 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Hi,

Two years ago (in comp.lang.modula2) there was a discussion about
whether it was possible to implement coroutines et al. using GNU
Pthreads. So I just thought I'd report that GNU Modula-2 now supports
this. The SYSTEM module implements the type PROCESS and the
procedures: TRANSFER, IOTRANSFER, NEWPROCESS and LISTEN.

Here is a snippet from the _limited_ documentation (apologies
for the texinfo control codes.

Gaius

[again it should be in place by 0:00 27th Aug BST]

The directory gm2/gm2-libs-coroutines contains a PIM @code{SYSTEM}
containing the @code{PROCESS} primitives built on top of GNU Pthreads.

The justification for this approach is that it provides a
@code{SYSTEM} compatible with Programming in Modula-2 [234] and the
Logitech 3.0 compiler. It also allows higher level executives to be
ported onto GM2 with little effort. The disadvantage with this
approach is that @code{IOTRANSFER} is not
preemptive. @code{IOTRANSFER} will only context switch when a call to
@code{LISTEN} is made or a call to @code{SYSTEM.TurnInterrupts} is
made.

In practice this limitation can be tolerated as long as processes
perform IO at some point (or wait for a timer interrupt) or call
@code{SYSTEM.TurnInterrupts}. But nevertheless a @code{LOOP}
@code{END} will starve all other processes. However the great
advantage is that GNU Modula-2 can offer users the ability to use
@code{IOTRANSFER}, @code{TRANSFER}, @code{NEWPROCESS} in user space
and on a multi-user operating system across many platforms.

The GNU Modula-2 @code{SYSTEM} works by utilizing the user context
switching mechanism provided by GNU Pthreads. @code{NEWPROCESS}
creates a new context, @code{TRANSFER} switches
contexts. @code{IOTRANSFER} is more complex. There is a support module
@code{SysVec} which provides pseudo interrupt vectors. These can
either be created from input/output file descriptors and also timer
events @code{timeval}. This vector is then passed to @code{IOTRANSFER}
which keeps track of which file descriptors and timevals are
active. When a call to @code{TurnInterrupts} or @code{LISTEN} is made
the sub system calls @code{pth_select} and tests for any ready file
descriptor or timeout. A ready file descriptor or timeout will
ultimately cause the backwards @code{TRANSFER} inside
@code{IOTRANSFER} to take effect.

See the @file{gm2/examples/executive} directory for an executive and
timerhandler module which provide higher level process creation,
synchronisation and interrupt handling routines. These libraries have
been tested with the examples shown in @file{gm2/examples/executive}
and @file{gm2/gm2-libs-coroutines}.

Users of these libraries and the libraries in
@file{gm2/examples/executive} must link their application against the
GNU Pthread library (typically by using @code{-lpth}).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]