Re: A new approach to multi-threading

From: Bob Nash <BNash_at_smud.org>
Date: Thu, 20 Jan 2000 06:46:14 -0800

        Ignorant question: What is the purpose of "0 >R ........ R> DROP ;"
in the definition of FORK? Is this for termination on a throw?
        -----Original Message-----
        From: SF Talk [SMTP:sftalk_at_forth.com]
        Sent: Wednesday, January 19, 2000 3:58 PM
        To: SF Talk
        Subject: A new approach to multi-threading

        Date: Wed, 19 Jan 2000 15:14:54 -0800
        From: "Rick VanNorman" <rvn_at_forth.com>
        Subject: A new approach to multi-threading

        For the group's consideration:

        OPTIONAL FORK An alternative to tasks.

        {
====================================================================
        (C) Copyright 1999 FORTH, Inc. www.forth.com Rick
VanNorman
        FORK, an alternative to tasks.
        ====================================================================
}

        :NONAME ( -- ) _PARAM_0 CATCH ExitThread ; 1 CB: FORKED

        : FORK ( xt -- handle ) 0 >R
>R 0 65536 FORKED R> 0 RP@ CreateThread R> DROP ;

        \\

        In SwiftForth, the callback mechanism builds a "virtual" forth
machine
        for code to execute on, complete with a user context and stacks.
This
        is exactly what a background thread needs to be and to do. So, I
have
        implemented FORK to do very simple multi-threading. Give FORK an
        xt to execute; it will run as a separate thread either forever, or
until
        it completes, or until it throws. This task is allowed to return;
it
        is not required to be an infinite loop.

        FORK returns the handle of the thread created. If the user desires
to
        manipulate the thread, he better keep up with the handle returned!

        For example,

        VARIABLE FOO

        : BAR 1000 0 DO 1 FOO +! 250 Sleep DROP LOOP ;

        ' BAR FORK .

.
Received on Wed Jan 19 2000 - 15:14:54 PST


Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 09-Feb-2012. Archive updated nightly.