The other responses answer your question, but I'll provide a little more
background.
The classic Forth multitasker (originally developed by Chuck and still
in use in many native & embedded Forths) is "cooperative" -- a task
voluntarily relinquishes the CPU. One advantage of this is that there is
far less context to save and restore, so task switches are much faster
than with pre-emptive algorithms. Another advantage is that the
programmer knows when the program is doing something that may cause a
task switch.
The disadvantage is that a task may "hog" the CPU and prevent other
tasks from having timely access. The compromise which makes the
cooperative algorithm work is that whenever a task performs an I/O
operation it must relinquish the CPU. This is brilliant because I/O
takes a long time, comparatively speaking, and in most applications
(especially control systems, for which Forth was originally designed)
there isn't a lot to do between I/O operations. So this makes very
efficient use of the CPU, making the majority of its cycles available
for doing real work.
One must take a broad view of what defines I/O: for example, writing a
character to a screen is I/O, even if the "screen" is in a local frame
buffer. And any drivers that the programmer adds must also follow the
rule. So long as everyone respects this rule, cooperative multitasking
is effortless and in over 30 years of application programming I don't
recall any problems.
There are several ways to implement this. One is the high-level word
PAUSE, which someone mentioned. PAUSE relinquishes the CPU for exactly
one pass through the task list. A more sophisticated way, appropriate in
an interrupt-driven system, is to deactivate the task when the I/O is
initiated, and let the interrupt driver that responds when the action is
completed set its status to be active again.
And Andrew makes an important point about BLOCK buffers: they must be
shared in a multitasking system, to avoid the possibility of multiple
copies of a block with different contents. Sound application design
avoids conflicts. It's true that most modern Forths that run under a
host OS don't use BLOCK for disk I/O, but blocks are, indeed, quite
useful for managing flash or other mass storage.
Cheers,
Elizabeth
--
==================================================
Elizabeth D. Rather (US & Canada) 800-55-FORTH
FORTH Inc.
+1 310.999.6784
5959 West Century Blvd. Suite 700
Los Angeles, CA 90045
http://www.forth.com
"Forth-based products and Services for real-time
applications since 1973."
==================================================