Here the code of "mt02.rex", changes (compared to "mt01.rex") in bold:

   say "--->" .context~name
   trace r
   t=.Test~new
   t~m1-- same as: t~send('M1'), waits for return t~m2-- same as: t~send('M2'), 
waits for return t~block-- wait for both methods to complete, -- same as: 
t~send('BLOCK'), waits for return ::class Test-- a test class ::attribute 
counter-- an attribute/an object variable ::method init-- constructor expose 
counter-- must be very first statement trace a
      say "arrived in:" .context~name
      counter=0 ::method m1-- guarded method expose counter-- must be very 
first statement trace a
     counter+=1 -- increase counter say "arrived in:" .context~name"before 
reply" *call **syssleep getSleepTime() **-- randomly sleep* reply ***tsk**=**1 **-- to show up 
in trace ****call **syssleep getSleepTime() **-- randomly sleep ****tsk**=**2 **-- to show up in 
trace *::method m2unguarded -- unguarded method trace a
     say "arrived in:" .context~name"before reply" ***call **syssleep getSleepTime() 
**-- randomly sleep *reply *call **syssleep getSleepTime() **-- randomly sleep 
*self~counter=self~counter-1 -- decrease counter ::method block-- block caller, if counter<>0 
expose counter-- must be very first statement guard on when counter=0 -- attribute used as control 
variable return 99 ::routine getSleepTime
      t=random(1,10)
      return t/1000

Trace output without thread number:

   ---> G:\tmp\orx\multithreading\mt02.rex
         3 *-* t=.Test~new
        15 *-* say "arrived in:" .context~name
   arrived in: INIT
        16 *-* counter=0
           >>>   "a TEST"
         4 *-* t~m1                 -- same as: t~send('M1'), waits for return
        21 *-* counter+=1          -- increase counter
        22 *-* say "arrived in:" .context~name "before reply"
   arrived in: M1 before reply
        23 *-* call syssleep getSleepTime() -- randomly sleep
        24 *-* reply
         5 *-* t~m2                 -- same as: t~send('M2'), waits for return
           >I> Method "M1" with scope "TEST" in package 
"G:\tmp\orx\multithreading\mt02.rex".
        31 *-* say "arrived in:" .context~name "before reply"
   arrived in: M2 before reply
        25 *-* tsk=1               -- to show up in trace
        32 *-* call syssleep getSleepTime() -- randomly sleep
        26 *-* call syssleep getSleepTime() -- randomly sleep
        27 *-* tsk=2               -- to show up in trace
        33 *-* reply
         6 *-* t~block              -- wait for both methods to complete,
           >I> Method "M2" with scope "TEST" in package 
"G:\tmp\orx\multithreading\mt02.rex".
        34 *-* call syssleep getSleepTime() -- randomly sleep
        35 *-* self~counter=self~counter-1  -- decrease counter
           >>>   "99"

Trace ouput with thread number:

   ---> G:\tmp\orx\multithreading\mt02.rex
         3 *- 1* t=.Test~new
        15 *- 1* say "arrived in:" .context~name
   arrived in: INIT
        16 *- 1* counter=0
           >> 1>   "a TEST"
         4 *- 1* t~m1                 -- same as: t~send('M1'), waits for return
        21 *- 1* counter+=1          -- increase counter
        22 *- 1* say "arrived in:" .context~name "before reply"
   arrived in: M1 before reply
        23 *- 1* call syssleep getSleepTime() -- randomly sleep
        24 *- 1* reply
         5 *- 1* t~m2                 -- same as: t~send('M2'), waits for return
           >I 2> Method "M1" with scope "TEST" in package 
"G:\tmp\orx\multithreading\mt02.rex".
        31 *- 1* say "arrived in:" .context~name "before reply"
   arrived in: M2 before reply
        25 *- 2* tsk=1               -- to show up in trace
        32 *- 1* call syssleep getSleepTime() -- randomly sleep
        26 *- 2* call syssleep getSleepTime() -- randomly sleep
        27 *- 2* tsk=2               -- to show up in trace
        33 *- 1* reply
         6 *- 1* t~block              -- wait for both methods to complete,
           >I 2> Method "M2" with scope "TEST" in package 
"G:\tmp\orx\multithreading\mt02.rex".
        34 *- 2* call syssleep getSleepTime() -- randomly sleep
        35 *- 2* self~counter=self~counter-1  -- decrease counter
           >> 1>   "99"

Multithreading trace output activated:

   ---> G:\tmp\orx\multithreading\mt02.rex
   R1   T1   A1                    3 *-* t=.Test~new
   R1   T1   A2    V1      1*     15 *-* say "arrived in:" .context~name
   arrived in: INIT
   R1   T1   A2    V1      1*     16 *-* counter=0
   R1   T1   A1                      >>>   "a TEST"
   R1   T1   A1                    4 *-* t~m1                 -- same as: 
t~send('M1'), waits for return
   R1   T1   A3    V1      1*     21 *-* counter+=1          -- increase counter
   R1   T1   A3    V1      1*     22 *-* say "arrived in:" .context~name "before 
reply"
   arrived in: M1 before reply
   R1   T1   A3    V1      1*     23 *-* call syssleep getSleepTime() -- 
randomly sleep
   R1   T1   A3    V1      1*     24 *-* reply
   R1   T1   A1                    5 *-* t~m2                 -- same as: 
t~send('M2'), waits for return
   R1   T2   A3    V1      1*        >I> Method "M1" with scope "TEST" in package 
"G:\tmp\orx\multithreading\mt02.rex".
   R1   T1   A4    V1      1      31 *-* say "arrived in:" .context~name "before 
reply"
   arrived in: M2 before reply
   R1   T2   A3    V1      1*     25 *-* tsk=1               -- to show up in 
trace
   R1   T1   A4    V1      1      32 *-* call syssleep getSleepTime() -- 
randomly sleep
   R1   T2   A3    V1      1*     26 *-* call syssleep getSleepTime() -- 
randomly sleep
   R1   T2   A3    V1      1*     27 *-* tsk=2               -- to show up in 
trace
   R1   T1   A4    V1      1      33 *-* reply
   R1   T1   A1                    6 *-* t~block              -- wait for both 
methods to complete,
   R1   T2   A4    V1                >I> Method "M2" with scope "TEST" in package 
"G:\tmp\orx\multithreading\mt02.rex".
   R1   T2   A4    V1             34 *-* call syssleep getSleepTime() -- 
randomly sleep
   R1   T2   A4    V1             35 *-* self~counter=self~counter-1  -- 
decrease counter
   R1   T1   A1                      >>>   "99"

---rony


_______________________________________________
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to