[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
another set of primitives for concurrency
For comparison with Chris Haynes's posting of the Scheme engine
operating system, here is a quick description of the concurrency
primitives used in MacScheme+Toolsmith. They aren't as useful
as engines for writing a metacircular interpreter, however.
To use the concurrency features, you have to say
You can say
to disable scheduling. The END-TASKING procedure doesn't kill any
tasks, so you can resume scheduling by calling BEGIN-TASKING again.
A RESET will kill all tasks and disable tasking. If an error occurs,
tasking continues while you're in the debugger, but if you quit out
of the debugger (instead of fixing the error and resuming) then a
RESET will be performed.
If a task reads from the keyboard when no characters are available,
a task switch occurs so another task can run while the one is waiting
for input. Tasks with time on their hands, such as a background task
that is monitoring the position of the mouse, can call
to let some other task do something productive in the meantime. The
approximate size of a time slice is determined by a global variable.
Tasks are created and run by
The <thunk> is called with no arguments and runs as a concurrent task.
The value returned by START-TASK is a task object. The task object
dies when <thunk> returns, or when someone calls KILL-TASKS on it:
(kill-tasks <task1> ...)
or when the task calls KILL-CURRENT-TASK. If all tasks die, then a
RESET is performed.
There is no hierarchy of tasks. Thus killing a task does not kill
tasks created by that task.
Synchronization is performed using side effects and
which calls <thunk> as an atomic action. The atomic action ends when
Interrupts are also executed uninterruptibly (with certain exceptions,
such as when the debugger is called as the result of an error). The
interrupt system is programmable, with dynamically installed handlers
written in Scheme, but that's another discussion. The main use of
interrupts is to implement interactive objects such as windows as part
of the Macintosh user interface.
Scheme source for the task scheduler and interrupt system is supplied
Peace, William Clinger