«previous next»
Multitasking
Windows is an inherently multitasked environment, operating at several levels:
- Multiple applications (e.g., Word, Excel, Netscape, SwiftForth) can be
launched and running concurrently. Each has its own resources (memory,
CPU registers and stacks, etc.). Each is a completely different program;
they are not sharing any code, although they might call some of the same DLLs.
They might also communicate with one another, but they are still separate programs.
- Multiple threads can be launched from within an application. A thread is
a piece of code (often a loop) that the Windows OS can be asked to execute
separately. The thread uses the resources of the application that launched
(and "owns") it, meaning it's executing code that resides in the owner's
memory, using its registers, etc. However, the code is running asynchronously
to the owning application, with the Windows OS controlling the scheduling
according to its priority with respect to others. The owning program launches
the thread and sets its priority; it can start and stop it, or kill it.
- Multiple windows can be launched by an application (or by one of its threads),
as well. These are considered "child windows." A child window has a procedure (WNDPROC)
that it executes, which is in many respects like an interrupt. It must enter,
initialize itself, perform whatever the event causing the interrupt demands, and exit.
The WNDPROC is not permitted to have an on-going behavior or loop, but runs solely
in response to events and messages.
A window (or a dialog box, which is a kind of window) is an instance of a
particular class of windows that the application has defined. Each has a handle.
When an event occurs, the OS sends a message to the application, which dispatches
it with the window's handle, and on receipt of the message the window's WNDPROC
will execute. It's an entirely event-driven paradigm.
A SwiftForth program can support both multiple threads and multiple windows.
A thread is in some respects similar to a pF/x or
SwiftOS background task, in
that it is given its own Forth stacks and user variables and is executing code
from within SwiftForth's dictionary. However, since the Windows OS controls
execution and "task switching," there is no equivalent of the PAUSE loop
found in pF/x or SwiftOS. At this time SwiftForth does not support multiple users,
where a user is a task with a private dictionary or individual interactive access via
the text interpreter to the shared dictionary.
Just as you can launch multiple instances of Windows applications such as
Word or Excel, you can also launch multiple instances of SwiftForth.
These function as completely independent programs, each of which might have
its own threads and/or windows. It is relatively easy for one SwiftForth
program to send messages to another.
«previous next»