Just a while ago I was asked by a student whether there is any easy way to 
create Rexx threads like
it is possible in Google's go. In go one would just prepend the word "go" 
before the name of the
function, that is to be executed on a separate thread. Here is the code example:

    func say(s string) { for i := 0; i < 5; i++ { time.Sleep(100 * 
time.Millisecond) fmt.Println(s)
    } } func main() { go say("world") say("hello") }

Now, I explained that if using methods, this would be possible. So a solution 
would be to define a
class with class methods and then use "reply" in the method or alternatively 
use the "start" message
to run a message on its own thread asynchroneously, giving the following 
example:

    .myFuncs~say1("world") say "main thread:" sysQueryProcess("tid") 
.myFuncs~say1("world", .true)
    .myFuncs~say1("hello", .false) say "---" .myFuncs~start("say2", "welt") -- 
"START" wird
    asynchron (in eigenem Thread ausgeführt) .myFuncs~send("say2", "hallo") say 
"---" ::class
    myFuncs ::method say1 class unguarded -- mit reply use arg s, bNewThread 
say "a) say1 thread:"
    sysQueryProcess("tid") "s=["s"]" if bNewThread then reply -- say "b) say1 
thread:"
    sysQueryProcess("tid") "s=["s"]" do i=1 to 5 call sysSleep .1 say s end 
::method say2 class
    unguarded use arg s say "say2 thread:" sysQueryProcess("tid") "s=["s"]" do 
i=1 to 5 call
    sysSleep .1 say s end

This works.

But how much easier would this be, if routines in ooRexx would allow for using 
"reply" (being
executed in unguarded mode)?

Then one would be able to code the "go"-example 1:1 as:

    call say "world", .true call say "hello", .false ::routine say use arg s, 
bOnNewThread if
    bOnNewThread then reply do i=1 to 5 call sysSleep .1 say s end

It is easier to read and easier to code, and would allow to transcribe 
go-programs that employ
multihreading to ooRexx in an almost 1:1 fashion!

---rony


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to