• Cooperative multitasking Forth for Linux?

    From Paul Rubin@21:1/5 to All on Tue Oct 11 00:35:25 2022
    Does anyone know of a Forth with traditional cooperative multitasking,
    that I can run under Linux? Not too worried about other features, just
    want to try benchmarking it against some other lightweight multitasking schemes. Thanks.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to no.email@nospam.invalid on Tue Oct 11 11:51:05 2022
    In article <8735bun77m.fsf@nightsong.com>,
    Paul Rubin <no.email@nospam.invalid> wrote:
    Does anyone know of a Forth with traditional cooperative multitasking,
    that I can run under Linux? Not too worried about other features, just
    want to try benchmarking it against some other lightweight multitasking >schemes. Thanks.

    See the library source of ciforth.
    There are two words that are of importance.
    CTA : clone task area, you want to have dictionary space, data stack
    and return stack cloned. That is the hard part.
    ciforth was designed to make this part easy.
    If your Forth is badly designed, you may have a hard time to
    program a CTA word.

    Once that is handled, the rest is portable.

    The basic idea is similar to mpe forths multitasking.
    1. create a data structure, a "task"
    2. pass an execution token to this word.

    If CTA is working well, you can execute different xt' within the task consecutively, building definitions in the dictionary space of this
    particular task. Then execute them.

    Note: If the purpose is to full use of cores, only pre-emptive
    multitasking using the __NR_clone system call, is any good.

    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to albert@cherry. on Fri Oct 14 02:14:07 2022
    albert@cherry.(none) (albert) writes:
    See the library source of ciforth.

    Thanks, I'll give that a try.

    Note: If the purpose is to full use of cores, only pre-emptive

    No I don't care about that, I specifically want to benchmark Forth
    cooperative multitasking (single cpu) against an interesting C coroutine
    scheme that someone posted.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Brian Fox@21:1/5 to Paul Rubin on Fri Oct 14 05:00:47 2022
    On Friday, October 14, 2022 at 5:14:09 AM UTC-4, Paul Rubin wrote:
    albert@cherry.(none) (albert) writes:
    See the library source of ciforth.
    Thanks, I'll give that a try.
    Note: If the purpose is to full use of cores, only pre-emptive
    No I don't care about that, I specifically want to benchmark Forth cooperative multitasking (single cpu) against an interesting C coroutine scheme that someone posted.

    Wouldn't it be more accurate to compare Forth co-routines to the C version? Aside from being cooperative, the traditional Forth systems are a real
    context switch. Co-routines, at least in Forth, are just a bit of return stack chicanery.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to Brian Fox on Fri Oct 14 09:20:57 2022
    Brian Fox <brian.fox@brianfox.ca> writes:
    Wouldn't it be more accurate to compare Forth co-routines to the C
    version? Aside from being cooperative, the traditional Forth systems
    are a real context switch. Co-routines, at least in Forth, are just a
    bit of return stack chicanery.

    Forth multtasking usually doesn't involve a hardware context switch if
    that's what you mean? What I think of as a coroutine (and what the C
    coroutine lib I mention does) is similar to what Forth's multitasker
    does, minus the scheduler (but the user has to supply that). I'm aware
    of a Forth "coroutine swap" word that maybe just swaps the TOS with the
    top of the return stack. Is that what you mean by return stack
    chicanery?

    This is the C library I was looking at, and the article has some
    benchmarks comparing it to various other languages, so I wanted to
    compare it with Forth:

    http://www.cofault.com/2022/10/usched-stackswap-coroutines-neither.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Brian Fox@21:1/5 to Paul Rubin on Sat Oct 15 08:23:19 2022
    On Friday, October 14, 2022 at 12:20:59 PM UTC-4, Paul Rubin wrote:
    Forth multtasking usually doesn't involve a hardware context switch if
    that's what you mean?

    I spin in circles with old machines so my knowledge is not current.
    I am not familiar with what a hardware context switch means in
    the "context" of an intel CPU these days or an ARM CPU.

    Old Forth multi-tasking would typically change the registers assigned
    to SP, RP and UP and in some cases a memory page swap for
    multi-user systems was employed.

    (The machine I play with actually does have a single instruction
    context switch via register windows in memory which I use for
    my cooperative multi-tasker)

    What I think of as a coroutine (and what the C
    coroutine lib I mention does) is similar to what Forth's multitasker
    does, minus the scheduler (but the user has to supply that).

    OK I see where you are coming from now.

    Of note: The old Forth systems in my experience didn't have a scheduler.
    The primitives did their own scheduling with PAUSE.
    Rather counter-intuitive to the mainstream thinking.
    This is not practical if your kernel does not have small well-
    behaved primitives designed with cooperation in mind.

    I'm aware
    of a Forth "coroutine swap" word that maybe just swaps the TOS with the
    top of the return stack. Is that what you mean by return stack
    chicanery?

    Yes this is what I meant.

    This is the C library I was looking at, and the article has some
    benchmarks comparing it to various other languages, so I wanted to
    compare it with Forth:

    http://www.cofault.com/2022/10/usched-stackswap-coroutines-neither.html

    Thank you. I will look this over.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to brian.fox@brianfox.ca on Sun Oct 16 11:56:30 2022
    In article <f9503f3e-82e2-41b5-9622-07fe0d608c3fn@googlegroups.com>,
    Brian Fox <brian.fox@brianfox.ca> wrote:
    On Friday, October 14, 2022 at 12:20:59 PM UTC-4, Paul Rubin wrote:
    Forth multtasking usually doesn't involve a hardware context switch if
    that's what you mean?

    I spin in circles with old machines so my knowledge is not current.
    I am not familiar with what a hardware context switch means in
    the "context" of an intel CPU these days or an ARM CPU.

    Hardware multi tasking revolves with _NR_clone primitive.
    Processors working in parallel, partly with shared memory
    using page table "and stuff".
    I have got >5 more speed from my 8 core machine.

    On windows 32 bit I used the CreateThread dll call.
    This doesn't work in windows 64, because information is geared
    towards c-programmers, forcing those to use wrappers/libraries.
    Those don't work unless you swallow the whole c-enchilada.
    In 32 bits I managed to hack this out.

    You can study it in the library of ciforth. It is just a couple
    of screens.
    The cloning of the task area is common to linux 32/64 and windows.
    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From S Jack@21:1/5 to Paul Rubin on Sun Oct 16 10:16:46 2022
    On Friday, October 14, 2022 at 11:20:59 AM UTC-5, Paul Rubin wrote:

    Forth multtasking usually doesn't involve a hardware context switch if

    I went from working with an 8080 to a 32-bit mini that had 16 sets of
    16 general-purpose registers. What luxury! A context switch was
    hardware switching in the desired set of 16 registers.

    The context switching was interesting but of little concern for me.
    The project only had two tasks, one multi-user terminal task and one
    message handling task. The latter was a state-machine that exchanged
    messages with hundreds of z-80's and handled up to 8,000 concurrent
    processes. The state-machine, not multi-tasking, provided the
    concurrency.

    When I first got into Forth, I was very interested in adding
    multi-tasking to my FigForth, which I did. I didn't have any need for
    it, nothing hanging off my home computer, so I only had a dancing
    stick figure, taking up valuable space, sharing the screen as I
    worked. That was quickly put aside and my interest in multi-tasking
    waned.

    Whenever I get a urge to implement one again, I always get side-tracked thinking of other possibilities such as making use of the host's
    background task to run additional Forths or other programs to function
    in a more loosely coupled manner. I have a coproc setup for running
    with Bash but again, don't have pressing need so don't do much with
    it.
    --
    me

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to S Jack on Sun Oct 16 12:37:15 2022
    S Jack schrieb am Sonntag, 16. Oktober 2022 um 19:16:48 UTC+2:
    On Friday, October 14, 2022 at 11:20:59 AM UTC-5, Paul Rubin wrote:

    Forth multtasking usually doesn't involve a hardware context switch if
    I went from working with an 8080 to a 32-bit mini that had 16 sets of
    16 general-purpose registers. What luxury! A context switch was
    hardware switching in the desired set of 16 registers.

    The context switching was interesting but of little concern for me.
    The project only had two tasks, one multi-user terminal task and one
    message handling task. The latter was a state-machine that exchanged
    messages with hundreds of z-80's and handled up to 8,000 concurrent processes. The state-machine, not multi-tasking, provided the
    concurrency.

    When I first got into Forth, I was very interested in adding
    multi-tasking to my FigForth, which I did. I didn't have any need for
    it, nothing hanging off my home computer, so I only had a dancing
    stick figure, taking up valuable space, sharing the screen as I
    worked. That was quickly put aside and my interest in multi-tasking
    waned.

    Whenever I get a urge to implement one again, I always get side-tracked thinking of other possibilities such as making use of the host's
    background task to run additional Forths or other programs to function
    in a more loosely coupled manner. I have a coproc setup for running
    with Bash but again, don't have pressing need so don't do much with
    it.

    In a token-based system, Forth core + application program can be as small
    as 1 k-plus for its byte-code image. Given a simple VM with all stacks and global variables in a packed structure, it is not difficult to switch between several running Forths in a round-robin fashion (through PAUSE) because
    every Forth instance consists only of its double-set of image and global stack/variables pack, with all sharing the same single VM. No big deal.

    It had been fun to monitor CPU- and memory load of 1 million parallel Forths running on a single PC (3 GB memory, Windows 7 32-bit).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to minf...@arcor.de on Sun Oct 16 14:09:07 2022
    "minf...@arcor.de" <minforth@arcor.de> writes:
    In a token-based system, Forth core + application program can be as small
    as 1 k-plus for its byte-code image. Given a simple VM with all stacks and global variables in a packed structure, it is not difficult to switch between several running Forths in a round-robin fashion (through PAUSE) because
    every Forth instance consists only of its double-set of image and global stack/variables pack, with all sharing the same single VM. No big deal.

    Do you mean no shared memory between the instances? Was there message
    passing? Was there any buffering for the mailboxes? What did you do
    about stopping them from being overrun, or using too much memory
    compared to the 1k or whatever?

    I usually think of a Forth multitasker as having separate D and R stacks
    per task, plus a user variable segment per task, plus a shared global
    memory area. Simple memory race conditions are avoided because the
    tasks aren't preemptable (they switch on PAUSE). You still need synchronization if you want longer duration transactions. Andrew Haley
    (who we haven't heard from in a while) implemented software
    transactional memory (STM) for a system like that a while back, but I
    don't know what its constraints were.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to Brian Fox on Sun Oct 16 14:16:24 2022
    Brian Fox <brian.fox@brianfox.ca> writes:
    I spin in circles with old machines so my knowledge is not current.
    I am not familiar with what a hardware context switch means in
    the "context" of an intel CPU these days or an ARM CPU.

    A workstation cpu these days generally has multiple hardware "contexts"
    where a context has its own set of hardware registers, page tables, etc. Typically on each CPU, there would be a context for the OS and another
    one for user programs. These days there are usually multiple CPUs
    (cores) or hardware threads (virtual CPUs). Context switching is
    typically done through something like a software interrupt, and it is
    fairly slow compared with normal machine instructions.

    (The machine I play with actually does have a single instruction
    context switch via register windows in memory which I use for
    my cooperative multi-tasker)

    Cool, can I ask what kind of machine?

    Of note: The old Forth systems in my experience didn't have a scheduler.
    The primitives did their own scheduling with PAUSE.

    When the code in a task executes PAUSE, it transfers control to some
    other code, that decides what task to run next. That other code is
    what I mean by scheduler. Traditionally Forth used round robin
    scheduling, but you could also imagine a Forth multitasker that let
    tasks have separate priority levels.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to Paul Rubin on Mon Oct 17 11:45:01 2022
    On 17/10/2022 8:16 am, Paul Rubin wrote:
    ...
    Traditionally Forth used round robin
    scheduling, but you could also imagine a Forth multitasker that let
    tasks have separate priority levels.

    Not seen it but there was an article in Dr. Dobbs:

    Andy Yuen - A Tiny Preemptive Multitasking Forth

    I imagine the vendors would have a good idea of what users' needs and
    wants in the field have been.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From minforth@arcor.de@21:1/5 to Paul Rubin on Sun Oct 16 23:19:14 2022
    Paul Rubin schrieb am Sonntag, 16. Oktober 2022 um 23:09:10 UTC+2:
    "minf...@arcor.de" <minf...@arcor.de> writes:
    In a token-based system, Forth core + application program can be as small as 1 k-plus for its byte-code image. Given a simple VM with all stacks and global variables in a packed structure, it is not difficult to switch between
    several running Forths in a round-robin fashion (through PAUSE) because every Forth instance consists only of its double-set of image and global stack/variables pack, with all sharing the same single VM. No big deal.
    Do you mean no shared memory between the instances? Was there message passing? Was there any buffering for the mailboxes? What did you do
    about stopping them from being overrun, or using too much memory
    compared to the 1k or whatever?

    There was a scheduler task 0 that fired up all other VMs and passed them
    the address of a shared heap memory object. The scheduler also kept
    a central repository of all instance exception handlers. Buffered I/O used available OS functions.

    The thing was used to experiment with genetic algorithms with agents
    that represented the mutating system. Each agent run in his own Forth
    instance. It was not a multi-user system.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From none) (albert@21:1/5 to no.email@nospam.invalid on Mon Oct 17 13:39:02 2022
    In article <87czarlbm4.fsf@nightsong.com>,
    Paul Rubin <no.email@nospam.invalid> wrote:
    "minf...@arcor.de" <minforth@arcor.de> writes:
    In a token-based system, Forth core + application program can be as small
    as 1 k-plus for its byte-code image. Given a simple VM with all stacks and >> global variables in a packed structure, it is not difficult to switch between
    several running Forths in a round-robin fashion (through PAUSE) because
    every Forth instance consists only of its double-set of image and global
    stack/variables pack, with all sharing the same single VM. No big deal.

    Do you mean no shared memory between the instances? Was there message >passing? Was there any buffering for the mailboxes? What did you do
    about stopping them from being overrun, or using too much memory
    compared to the 1k or whatever?

    I meant shared memory. The original dictionary is common, as is the
    buffers that are allocated before creating tasks.


    I usually think of a Forth multitasker as having separate D and R stacks
    per task, plus a user variable segment per task, plus a shared global
    memory area. Simple memory race conditions are avoided because the
    tasks aren't preemptable (they switch on PAUSE).
    You are right about the setup. The task are pre-emptable,
    but cooperating. It is not linux where pre-empting means you
    have to terminate tasks that are not running properly.
    So pre-empting is quite similar to traditional mult-tasking in
    forth that a task will only be terminated in a regular fashion
    by itself or a master task designed to handle that.

    You still need
    synchronization if you want longer duration transactions. Andrew Haley
    (who we haven't heard from in a while) implemented software
    transactional memory (STM) for a system like that a while back, but I
    don't know what its constraints were.

    I use synchronization through shared memory.
    With care this worked well. What are spin locks else than
    synchronisation through shared memory?

    Groetjes Albert
    --
    "in our communism country Viet Nam, people are forced to be
    alive and in the western country like US, people are free to
    die from Covid 19 lol" duc ha
    albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Brian Fox@21:1/5 to Paul Rubin on Mon Oct 17 08:17:33 2022
    On Sunday, October 16, 2022 at 5:16:26 PM UTC-4, Paul Rubin wrote:

    Cool, can I ask what kind of machine?
    TMS9900 :-)

    When the code in a task executes PAUSE, it transfers control to some
    other code, that decides what task to run next. That other code is
    what I mean by scheduler. Traditionally Forth used round robin
    scheduling, but you could also imagine a Forth multitasker that let
    tasks have separate priority levels.

    OK. I see what you mean.
    The typical level of that control is pretty trivial.
    The task is asleep and so skipped in the round-robin queue or awake
    and it runs.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to Brian Fox on Mon Oct 17 11:50:38 2022
    Brian Fox <brian.fox@brianfox.ca> writes:
    The typical level of that control is pretty trivial.
    The task is asleep and so skipped in the round-robin queue or awake
    and it runs.

    I remember reading that Polyforth stayed cpu busy even if no tasks were runnable. These days you would put the scheduler and cpu to sleep if
    there were no runnable tasks. It would sleep until there was a hardware interrupt, such as a timer tick.

    Unix (idk about Linux) had "wait channels" (wchan, basically arbitrary integers, conventionally memory addresses) that processes could sleep
    on. If you ran "wakeup(w)" then all processes sleeping on wait channel
    w would awaken. I don't know how the kernel found those processes.
    Early on, it may have scanned the whole proc table, since memory on the
    PDP-11 was scarce and the number or processes necessarily couldn't be
    very large. These days I guess you'd want a fancier lookup structure.

    ISTM that a Forth multitasker might also want something like that. The coroutine library that I linked to appears designed to handle millions
    of tasks, but the typical MCU Forth app that I'm imagining might have
    5-10 tasks that all run through the app's entire duration.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Brian Fox@21:1/5 to Paul Rubin on Mon Oct 17 14:00:47 2022
    On Monday, October 17, 2022 at 2:50:40 PM UTC-4, Paul Rubin wrote:
    Brian Fox <bria...@brianfox.ca> writes:
    The typical level of that control is pretty trivial.
    The task is asleep and so skipped in the round-robin queue or awake
    and it runs.
    I remember reading that Polyforth stayed cpu busy even if no tasks were runnable. These days you would put the scheduler and cpu to sleep if
    there were no runnable tasks. It would sleep until there was a hardware interrupt, such as a timer tick.

    Unix (idk about Linux) had "wait channels" (wchan, basically arbitrary integers, conventionally memory addresses) that processes could sleep
    on. If you ran "wakeup(w)" then all processes sleeping on wait channel
    w would awaken. I don't know how the kernel found those processes.
    Early on, it may have scanned the whole proc table, since memory on the PDP-11 was scarce and the number or processes necessarily couldn't be
    very large. These days I guess you'd want a fancier lookup structure.

    ISTM that a Forth multitasker might also want something like that. The coroutine library that I linked to appears designed to handle millions
    of tasks, but the typical MCU Forth app that I'm imagining might have
    5-10 tasks that all run through the app's entire duration.

    Yes if you put all the tasks to sleep in PolyForth there would still be CPU activity. It would be PAUSE running in an endless loop. :-)

    Hardware interrupts were used in PolyForth for time critical code.
    Typically reading a byte and stuffing into a queue or some such thing.
    It would be pretty straightforward to do something else I should think.

    In the real world a primary console would be running and have almost
    100% of the CPU if everything else goes to sleep.

    My system has an MTOOLS file with WAKEALL & STOPALL and
    assumes the primary Forth console is G_d. It just traverses the round
    robin links and sets/resets the TFLAG user variable in each task.
    (You can kill the console if you want to but then the universe ends...)

    The entire task switcher for the 9900 is 4 instructions plus NEXT.
    One instruction to context switch and 3 more to test a flag and jump.
    Here is the file since you seem curious. https://github.com/bfox9900/CAMEL99-ITC/blob/master/LIB.ITC/MTASK99.FTH

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to Brian Fox on Mon Oct 17 15:36:44 2022
    Brian Fox <brian.fox@brianfox.ca> writes:
    Yes if you put all the tasks to sleep in PolyForth there would still be CPU activity. It would be PAUSE running in an endless loop. :-)

    I guess cpu's in that era didn't have low powered sleep modes.
    Otherwise you'd just drop into one until an interrupt came.

    Here is the file since you seem curious. https://github.com/bfox9900/CAMEL99-ITC/blob/master/LIB.ITC/MTASK99.FTH

    Thanks, I'll try to understand this. What did you do about task to task communication? In systems like Erlang, sometimes there are unbounded
    queues, hopefully with some back pressure to prevent getting flooded.
    That seems a bit extravagant for Forth. In Brad Rodriguez's example
    there was a single mailbox cell per task, but that seems inadequate,
    since you could deadlock easily.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to Paul Rubin on Tue Oct 18 11:57:24 2022
    On 18/10/2022 9:36 am, Paul Rubin wrote:
    Brian Fox <brian.fox@brianfox.ca> writes:
    Yes if you put all the tasks to sleep in PolyForth there would still be CPU >> activity. It would be PAUSE running in an endless loop. :-)

    I guess cpu's in that era didn't have low powered sleep modes.
    Otherwise you'd just drop into one until an interrupt came.

    IIRC current offerings from Forth Inc do exactly that - loops several
    times and if nothing is going on, drop to sleep mode.


    Here is the file since you seem curious.
    https://github.com/bfox9900/CAMEL99-ITC/blob/master/LIB.ITC/MTASK99.FTH

    Thanks, I'll try to understand this. What did you do about task to task communication? In systems like Erlang, sometimes there are unbounded
    queues, hopefully with some back pressure to prevent getting flooded.
    That seems a bit extravagant for Forth. In Brad Rodriguez's example
    there was a single mailbox cell per task, but that seems inadequate,
    since you could deadlock easily.

    Elizabeth describes the system Forth Inc uses here: https://groups.google.com/g/comp.lang.forth/c/88t12ePk_eg/m/NFKqe-Hh79EJ

    It's likely discussed in the docs that come with SwiftX.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Rubin@21:1/5 to dxforth on Mon Oct 17 19:37:12 2022
    dxforth <dxforth@gmail.com> writes:
    Elizabeth describes the system Forth Inc uses here: https://groups.google.com/g/comp.lang.forth/c/88t12ePk_eg/m/NFKqe-Hh79EJ
    It's likely discussed in the docs that come with SwiftX.

    Thanks, this is a traditional low level lock. I was hoping for
    something like mailboxes as a built-in feature, that allow tasks to
    communicate with each other by message passing. Brad Rodriguez's system
    has that, but each task's mailbox is just a single cell, iirc.
    I think that can lead to some problems. I will think about it more.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dxforth@21:1/5 to Paul Rubin on Tue Oct 18 15:34:25 2022
    On 18/10/2022 1:37 pm, Paul Rubin wrote:
    dxforth <dxforth@gmail.com> writes:
    Elizabeth describes the system Forth Inc uses here:
    https://groups.google.com/g/comp.lang.forth/c/88t12ePk_eg/m/NFKqe-Hh79EJ
    It's likely discussed in the docs that come with SwiftX.

    Thanks, this is a traditional low level lock. I was hoping for
    something like mailboxes as a built-in feature, that allow tasks to communicate with each other by message passing. Brad Rodriguez's system
    has that, but each task's mailbox is just a single cell, iirc.
    I think that can lead to some problems. I will think about it more.

    Rodriguez does say it was a simple example that could be extended in various ways if required. Why 'built-in' when you can add just what you need.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Brian Fox@21:1/5 to Paul Rubin on Mon Oct 17 22:49:54 2022
    On Monday, October 17, 2022 at 6:36:48 PM UTC-4, Paul Rubin wrote:
    Brian Fox <bria...@brianfox.ca> writes:
    Yes if you put all the tasks to sleep in PolyForth there would still be CPU activity. It would be PAUSE running in an endless loop. :-)
    I guess cpu's in that era didn't have low powered sleep modes.
    Otherwise you'd just drop into one until an interrupt came.
    Here is the file since you seem curious. https://github.com/bfox9900/CAMEL99-ITC/blob/master/LIB.ITC/MTASK99.FTH
    Thanks, I'll try to understand this. What did you do about task to task communication? In systems like Erlang, sometimes there are unbounded
    queues, hopefully with some back pressure to prevent getting flooded.
    That seems a bit extravagant for Forth. In Brad Rodriguez's example
    there was a single mailbox cell per task, but that seems inadequate,
    since you could deadlock easily.

    For messaging I put something together with single cell per task.
    I found the idea years ago in a Forth Dimensions Mag.
    The sender blocks until the mailbox cell is emptied by the rcvr.
    Adding a queue would not be very difficult. Never needed that level.

    https://github.com/bfox9900/CAMEL99-ITC/blob/master/LIB.ITC/MAILBOX.FTH

    To be honest for one way communication, many times a simple global
    variable is all that is required since each task will access it at different times.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marcel Hendrix@21:1/5 to Paul Rubin on Tue Oct 18 09:28:53 2022
    On Tuesday, October 18, 2022 at 4:37:15 AM UTC+2, Paul Rubin wrote:
    [..]
    Thanks, this is a traditional low level lock. I was hoping for
    something like mailboxes as a built-in feature, that allow tasks to communicate with each other by message passing. Brad Rodriguez's system
    has that, but each task's mailbox is just a single cell, iirc.
    I think that can lead to some problems. I will think about it more.

    iForth uses the transputer hardware / software Occam primitives (but does not HALT on link errors :-)
    Communications between cores/threads/computers is done with OS sockets. Multi-tasking works with pre-emptive threads (OS based). A task has its own stacks (data, return, system, locals, FPU) and its own dictionary (tasks can compile).

    iForth32 had PAUSE-based multitasking in addition to the pre-emptive stuff. Hanno removed this from iForth64 but I don't miss it much.

    In hindsight, the above is gigantic overkill (for my graphics/sound needs). Current multi-core CPU's can do jobs that I needed a few networked pc's for
    in the old days. To synchronize that stuff in a single box is easy.

    -marcel

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)