Question is how to multitask on a small embedded target. One way is the >traditional cooperative multitasker with a shared dictionary plus task >variables.
Another way is time slicing multiple interpreters, each with its own
data dictionary (all variables are task variables). There would be a
shared read-only dictionary for code and constants, and a mailbox scheme
for IPC.
This question is more about shared vs non-shared than cooperative vs >preemptive. The latter would be Erlang-style preemptive, i.e. avoiding
most locking hazards by using mailboxes instead of memory sharing.
Does anyone do it this way? Is the overhead substantial?
The other situation is that you take advantage of multiple cores
to speed up the calculation. There you use the fork system call.
albert@spenarnc.xs4all.nl writes:
The other situation is that you take advantage of multiple cores
to speed up the calculation. There you use the fork system call.
The idea here is to multitask on an MCU with around 2kB of memory, so no
OS. Just a few tasks to monitor a pushbutton, control a LED, and some similar things.
Question is how to multitask on a small embedded target. One way is the >traditional cooperative multitasker with a shared dictionary plus task >variables.
Another way is time slicing multiple interpreters, each with its own
data dictionary (all variables are task variables). There would be a
shared read-only dictionary for code and constants, and a mailbox scheme
for IPC.
This question is more about shared vs non-shared than cooperative vs >preemptive. The latter would be Erlang-style preemptive, i.e. avoiding
most locking hazards by using mailboxes instead of memory sharing.
Does anyone do it this way? Is the overhead substantial?
Paul Rubin <no.email@nospam.invalid> writes:
Question is how to multitask on a small embedded target. One way is the >>traditional cooperative multitasker with a shared dictionary plus task >>variables.
Another way is time slicing multiple interpreters, each with its own
data dictionary (all variables are task variables). There would be a >>shared read-only dictionary for code and constants, and a mailbox scheme >>for IPC.
This question is more about shared vs non-shared than cooperative vs >>preemptive. The latter would be Erlang-style preemptive, i.e. avoiding >>most locking hazards by using mailboxes instead of memory sharing.
Does anyone do it this way? Is the overhead substantial?
Gforth is not for small embedded systems, but anyway, the development
version does multi-tasking by mapping each task to a POSIX thread
(within one process), with the classical USER variable mechanism for >task-local variables, multiprocessing/preemption (coming from POSIX
threads), and an actor-like mechanism for communicating between tasks
and for synchronizing them (there are also other synchronizing
mechanisms). The messages that the actor-like mechanism delivers to
the mailbox of a task are xts that the receiving task executes. You
can read about that in https://net2o.de/gforth/Multitasker.html.
Concerning the idea of replicating all variables and buffers in each
task, that seemed too expensive in memory for Gforth, and I expect
that it is considered too expensive all the more for small embedded
targets. For Gforth we want to be able to support a huge number of
tasks (although the current implementation with one pthread per task
is probably too expensive for that, too, but a future implementation
can fix that), for a small embedded system you may only want to have a
few tasks, but even then you don't want to waste memory on replicating >buffers that are only used in one task. There is a reason why Forth
has both VARIABLE and USER.
- anton--
Concerning the idea of replicating all variables and buffers in each
task, that seemed too expensive in memory for Gforth
On 2025-07-29, Paul Rubin wrote:
albert@spenarnc.xs4all.nl writes:
The other situation is that you take advantage of multiple cores
to speed up the calculation. There you use the fork system call.
The idea here is to multitask on an MCU with around 2kB of memory,
so no OS.
Just a few tasks to monitor a pushbutton, control a LED, and some
similar things.
Gforth is not for small embedded systems, but anyway, the development
version does multi-tasking by mapping each task to a POSIX thread
(within one process), with the classical USER variable mechanism for task-local variables, multiprocessing/preemption (coming from POSIX
threads), and an actor-like mechanism for communicating between tasks
and for synchronizing them (there are also other synchronizing
mechanisms). The messages that the actor-like mechanism delivers to
the mailbox of a task are xts that the receiving task executes. You
can read about that in https://net2o.de/gforth/Multitasker.html.
On 7/29/2025 12:49 AM, Anton Ertl wrote:
The messages that the actor-like mechanism delivers toThe link above says "Gforth offers two multitaskers: a traditional, cooperative round-robin multitasker, and a pthread-based multitasker ... " then has additional links to Pthreads and Cilk. Is the traditional multitasker at the Cilk link?
the mailbox of a task are xts that the receiving task executes. You
can read about that in https://net2o.de/gforth/Multitasker.html.
Buzz McCool <buzz_mccool@yahoo.com> writes:
On 7/29/2025 12:49 AM, Anton Ertl wrote:" then has additional links to Pthreads and Cilk. Is the traditional >multitasker at the Cilk link?
The messages that the actor-like mechanism delivers toThe link above says "Gforth offers two multitaskers: a traditional, >cooperative round-robin multitasker, and a pthread-based multitasker ...
the mailbox of a task are xts that the receiving task executes. You
can read about that in https://net2o.de/gforth/Multitasker.html.
No. The Cilk stuff is based on the pthreads stuff. The traditional >multitasker is undocumented, unfortunately. Maybe we should not
mention it. Those who like to use it will find it and will know how
to use it.
- anton
The only essential difference between COT and PRE is that you must
do PAUSE in COT. The other differences can be anything.
I don't think it makes sense to talk about COT in general, because
the most important use case has disappeared, and there are no
canonical examples any more.
albert@spenarnc.xs4all.nl writes:<SNIP>
I don't think it makes sense to talk about COT in general, because
the most important use case has disappeared, and there are no
canonical examples any more.
What was the most important use case?
I don't think it makes sense to talk about COT in general, because
the most important use case has disappeared, and there are no
canonical examples any more.
Have multiple users connected to one cpu, e.g. onve upon a time with
vt100's connected to a PDP11.
I don't think it makes sense to talk about COT in general, because
the most important use case has disappeared, and there are no
canonical examples any more.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,064 |
Nodes: | 10 (0 / 10) |
Uptime: | 153:20:23 |
Calls: | 13,691 |
Calls today: | 1 |
Files: | 186,936 |
D/L today: |
2,526 files (731M bytes) |
Messages: | 2,411,055 |